Enterprise Architect from Sparx Systems allows you to integrate NUnit unit tests into your project. As the new build of EA (8.863) now supports .net 4.0 I revisited this functionality and prepared a little walkthrough.

All of this work has been done on Windows 7 x64 with Visual Studio 2010.  In order to have as little troubles as possible you have to go for the x86 version of the tools so everything works nicely. As EA is a x86 Application using the x64 Tools will not work.

In order run this you need at least NUnit 2.5.5 – where as I went with the latest Version NUnit 2.5.7

I prepared a simple demo solution in Visual Studio 2010 that consists of an Accounts an Accounts Test Project.

img3

Using Resharper from Jetbrains I can run my unit tests nicely inside Visual Studio 2010

img4

Next I generate a new Project inside Enterprise Architect. Inside the new Model I than “Add a Package” named  “AccountsClassModel”.

img6

img7

A right click on this new Package “AccountsClassModel” allows me to call the “Import Source Directory” function of Enterprise Architect.

img8

As my Visual Studio Solution is in “C:\Source\Accounts” I specify this directory as the Root Directory. As my 2 Projects reside in separate folders below the root folder it is important to check the “Recursively Process Subdirectories” Option

img9

It takes a little while for EA to import the sources and generate the required items inside our Package.

imgA

After the Import is done – we will see a similar structure in the Project Browser as we did before in Visual Studio.

imgB

To be able to build, configure and run stuff from inside EA we need to show the “Debugger” Window.

imgD

Inside the “Debugger” Window have to configure “Package Build Scripts” – those Scripts tell EA what to do when we “Build” or “Run” the solution.

imgE

When this is called for the first time we will see an empty list. By pressing “Add” we can move forward to con figure the scripts.

imgF

The first “Tab” that is interesting for us is the “Build” one. We use msbuild.exe to compile the Solution just like Visual Studio is doing it.

%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Accounts.sln /Target:Rebuild

img10

After hitting “Ok” we can run our script from the Debug Window using the context menu.

img11

If everything is setup correctly we should see 0 Errors in the “Build” Tab of the “Output” Window.

img12

We can easily go back to editing our Script with the “Edit Script” option from the context menu.

img14

As I am running an x64 setup I have to make sure the .net .dll’s are compiled for x86 – therefore we need to enhance the command line from before a little bit.

%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Accounts.sln /Target:Rebuild /Property:Config=Debug;Platform=x86

img15

As we have prepared our Visual Studio Solution for x86 compilation we will receive an error when we try to compile the solution now.

img1B

So wee need to go back to Visual Studio’s “Configuration Manager” and add a new “Solution Platform”.

img16

After this step the Dialog should look like this. Don’t forget to save the Solution in Visual Studio. – If you know recompile with the Build Script from EA the package should be built fine.

img18

Now we can configure Nunit to run with Enterprise Architect – be careful in defining the x86 versions of the tools so it will work on x64 computers.

“C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\nunit-console-x86.exe” AccountsTest\bin\x86\Debug\AccountsTest.dll

Don’t forget to select the correct “Output Parser” – which is “NUnit”

img24

Next we need to show the “Testing” Window inside Enterprise Architect.

img26

The “Testing” Window will look empty – so let’s go and run some tests!

img25

5 Test Cases could be run and they have been added to the Model.

img28

Visiting the “Unit” Tab of the Testing Window will now show the test results from our NUnit execution.

img2A