Set Up Unit Testing

In order to use unit testing in Enterprise Architect, you must first set it up. This happens in two parts.

Firstly the appropriate tests must be defined. Enterprise Architect is able to help with this. 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.

The following is an NUnit example in C# that is followed through the rest of this topic, 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);

       }

}

This code can be reverse engineered into Enterprise Architect so that Enterprise Architect can record all test results against this Class.

Once the unit tests are set up, you can then set up the Build and Test scripts to run the tests. These scripts must be set up against a package.

The sample above can be called by setting up the Package Build Scripts dialog as follows.

testScript_nunit2

If Enterprise Architect is to handle unit testing, it is important that you select the Capture Output checkbox and select the appropriate Output Parser for the testing. Without doing this you won't see the program output and therefore you cannot open the source at the appropriate location.