Skip to content

weianweigan/SldWorks.TestRunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SolidWorks.TestRunner

SolidWorks.TestRunner is a simple Addin for SolidWorks to run unit tests from a specified test assembly. The test framework used is NUnit v3.

Install

DownLoad

Click *.bat file to Install or UnInstall.

Getting started

The Addin hooks in the Taskpane of SolidWorks.

By choosing your testing assembly, the view will show all your tests.

Select the node you want to test and press the ‘Run’. All tests below the selected node will be executed.

Write Tests

Create a test project in your solution and get the NUnit nuget package.

Let’s have a look to the SampleTest class. As you see, test are marked by the NUnit Attribute ‘Test’. Also ‘SetUp’ and ‘TearDown’ Attributes are supported.

public class SampleTest
{
    [SetUp]
    public void RunBeforeTest()
    {
        Console.WriteLine( $"Run 'SetUp' in {GetType().Name}" );
    }
 
    [TearDown]
    public void RunAfterTest()
    {
        Console.WriteLine( $"Run 'TearDown' in {GetType().Name}" );
    }
 
    [Test]
    public void PassTest()
    {
        Assert.True( true );
    }
 
    [Test]
    public void FailTest()
    {
        Assert.True( false, "This Test should fail!" );
    }
}

And now we are happy, almost. It would be nice if we can open a file in SolidWorks and make some test with it. This is not easy because we need the ISldWorks API Interface of SolidWorks, but we don’t have it available at this point. To get the API Interface, change the signature of your Test Method. The SldWorks.TestRunner will inject the desired object in the Test, SetUp or TearDown Method.

[Test]
public void MultiParameterTest1(ISldWorks swApp)
{
    Assert.IsNotNull(swApp);
    swApp.SendMsgToUser("Hello SolidWorks");
}

In your test, you have access to it, and your able to make stuff with it (ex. swApp.NewDocument(partTemPath, 0, 0, 0) as IPartDoc)

License

MIT

Thanks

  1. Base on Revit.TestRunner.

  2. xcad used to implement a SolidWorks addin.

  3. MahApps.Metro -- UI Controls