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.
Using Resharper from Jetbrains I can run my unit tests nicely inside Visual Studio 2010
Next I generate a new Project inside Enterprise Architect. Inside the new Model I than “Add a Package” named “AccountsClassModel”.
A right click on this new Package “AccountsClassModel” allows me to call the “Import Source Directory” function of Enterprise Architect.
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
It takes a little while for EA to import the sources and generate the required items inside our Package.
After the Import is done – we will see a similar structure in the Project Browser as we did before in Visual Studio.
To be able to build, configure and run stuff from inside EA we need to show the “Debugger” Window.
Inside the “Debugger” Window have to configure “Package Build Scripts” – those Scripts tell EA what to do when we “Build” or “Run” the solution.
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.
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
After hitting “Ok” we can run our script from the Debug Window using the context menu.
If everything is setup correctly we should see 0 Errors in the “Build” Tab of the “Output” Window.
We can easily go back to editing our Script with the “Edit Script” option from the context menu.
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
As we have prepared our Visual Studio Solution for x86 compilation we will receive an error when we try to compile the solution now.
So wee need to go back to Visual Studio’s “Configuration Manager” and add a new “Solution Platform”.
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.
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”
Next we need to show the “Testing” Window inside Enterprise Architect.
The “Testing” Window will look empty – so let’s go and run some tests!
5 Test Cases could be run and they have been added to the Model.
Visiting the “Unit” Tab of the Testing Window will now show the test results from our NUnit execution.
Nevertheless one needs to be carefull using this Feature – I have seen EA reporting False-Positives in the Testing pane with some combinations of the Tools
Save combination:
.net 3.5 – with Nunit 2.4.8
A combination that seems to Work nicely is NUnit 2.4.x with .net 3.5 – the NUnit 2.5.x with .Net 4.0 seems to report false-positives most of the time
thanks for the post
thanks!
Wow, thank you. I always wanted to write in my site something like that. Great job.
Hello, I found your blog in a new directory of blogs. I don’t know how your blog came up, must have been a typo. Your blog looks good, have a nice day.
There are some fascinating deadlines in this article but I don’t know if I see all of them heart to heart. There is some validity but I’ll take maintain opinion till I look into it further. Good article , thanks and we wish more! Added to FeedBurner as effectively
Very good site, thank you so much for your time in writing the posts. Like!