Prev Next

Set Up Unit Testing

This topic explains the actions you should take in setting up Unit Testing, after having downloaded and installed the JUnit and/or NUnit applications.

Actions

Action

Details

See also

Create Unit Test Stubs

By using the JUnit or NUnit transformations and code generation you can create test method stubs for all of the public methods in each of your Classes.

(TestFixture)

public class CalculatorTest

{

     (Test)

     public void testAdd(){

     }

     (Test)

     public void testDivide(){

     }

     (Test)

     public void testMultiply(){

     }

     (Test)

     public void testSubtract(){

     }

}

Unit Testing JUnit Transformation NUnit Transformation Generate Source Code

Define Test Cases

Write your unit test in the generated code stubs (either in Enterprise Architect or your preferred IDE).

This is an NUnit example in C#, although it could also be any other .NET language, or Java and JUnit.

(TestFixture)

public class CalculatorTest

{

     (Test)

     public void testAdd(){

          Assert.AreEqual(1+1,2);

     }

     (Test)

     public void testDivide(){

          Assert.AreEqual(2/2,1);

     }

     (Test)

     public void testMultiply(){

          Assert.AreEqual(1*1,1);

     }

     (Test)

     public void testSubtract(){

          Assert.AreEqual(1-1,1);

     }

}

Alternatively, if you have not performed an xUnit transformation, you can reverse engineer the code into Enterprise Architect so that the system can record all test results against this Class.

Compile Your Code

Check that the source code being tested compiles without errors, so that the test scripts can be run against it.

Set up the Test Scripts

Set up the Test scripts against the required Package, and then run the tests.

Add Testing Command Run Unit Tests