Tutorial – NUnit and Sequence Diagram Recording in Enterprise Architect 9.3

Enterprise Architect from Sparx Systems can be a real Swiss army knife for .net developers! Most of the stuff shown will also work with a Java environment.
I did already a series of blog posts around this type of topics. All of them are based around EA 8. As a lot of stuff changed since EA 8, the release of EA 9.3 motivated to rework the tutorial to reflect the changes.

We regularly use these techniques to find issues in large IOC (Inversion of Control) architectures. Where many modules are loaded dynamically and simple test beds like console runners and unit tests are your only chance to isolate the problematic parts in the source code.

I try to offer a simple explanation and step by step tutorial – should you have feedback or additional tips and tricks I am very happy to incorporate them in this guide.

The old posts are still available:
Integrating NUNIT in EA
Recording Sequence Diagrams with EA

You can download my sample project from here. Please note that everything is configured for specific paths.

Solution Directory: C:\Source\Accounts\src\Accounts
Model Directory: C:\Source\Accounts\model

As you work with this guide it will be pretty easy for you to customize the location Winking smile.

Preparing for x64 operating system

If you are running a x64 operating system you need to make sure that all of your code is compiled for x86 as Enterprise Architect is an x86 application – it will not work otherwise.

Open the Accounts.sln from C:\Source\Accounts\src\Accounts in Visual Studio 2008 and make sure you modify the solution correctly.

image

image

image

Now it should look like this:

image

Creating the Accounts.eap Model

Open Enterprise Architect 9.3 and create Accounts(x).eap in C:\Source\Accounts\model folder (Accounts.eap is there for reference) – Attention file path may vary.

Create a Package – and choose “Import Source directory…”.
image

Choose C# and point it to the C:\Source\Accounts\src\Accounts directory!

image

After the import the project browser should look like this:

image

Preparing the Execution Analyzer

Click on the before created Package (here “Classes”) and choose Execution Analyzer.

image

The following message should show up – just click “Yes”.

image

Now we need to configure the build to work from inside Enterprise Architect.

The command line should look like this:  (if you configured everything as described above)
%windir%\Microsoft.NET\Framework\v3.5\msbuild.exe Accounts.sln /Target:Rebuild /Property:Config=Debug;Platform=x86

build config
Change the setting on top to “Process” and specify the DefaultDirectory to your /src/Accounts folder and choose parse output to .net – That’s it.

Let’s build from inside Enterprise Architect

Right click on the package and choose build.

image

In the output window you should see something like below.

image

You built your first code using EA! Congratulations!

Preparing for using NUnit

Next make sure you have NUnit installed. If not download it from there:
http://launchpad.net/nunitv2/2.5/2.5.7/+download/NUnit-2.5.7.10213.msi
We need to install it because we will use the  console runner.
Next we configure the Test Tab of the Execution analyzer depending on os version we need
“C:\Program Files(x86)\NUnit 2.5.7\bin\net-2.0\nunit-console-x86.exe” AccountsTest\bin\x86\Debug\AccountsTest.dll
or
“C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console-x86.exe” AccountsTest\bin\x86\Debug\AccountsTest.dll

image

Don’t forget to specify everything as on the screenshot above!
If you have troubles check your NUnit-console path.
Don’t check the “BUILD FIRST” OPTION!  – there seems to be a problem when this option is checked.

Running NUnit from inside Enterprise Architect

In the Execution Analyzer window right click on “Model.Classes” and run “Test”.

image

Next you need to open the testing window!

image

Navigate to the class AccountTest in Project Browser

image
And you will see the following in the Test Window.

image

ATTENTION: As always, this type of features needs to be tested for your specific environment – nothing worth than a Unit Test integration reporting false positives!
My current Setup EA 9.3 and NUNIT 2.5.7 works nicely.
Right click on AccountTest in the Project Browser and select “View Source Code…”

Let’s play with line 38 – and comment it out or in

image

In the Execution Analyzer.
* Call Build and then
* Call Test
Go back to the “Testing” window with AccountTest selected in the Project Browser.

image

ATTENTION: The TESTING Window might not been updated automatically. If so, you need to move back and open it again after running the unit tests.

Ok – goal one is achieved. We successfully integrated unit test running capabilities into Enterprise Architect.

Recording Sequence Diagrams with EA via the Debugger

We could use the unit test for this purpose – but for simplicity and to be able to try this alone – I use the AccountsConsole program included in the sample.

Choose program.cs in Project Browser and hit F12 to view the source code:

image

I already added a start (line 12) and end (line 26)  recording marker in the source editor.

To manage markers you right click in the gray bar beside the line number and choose one or the other option.

image

Now we have to configure the debugger. For this double click “Model.Classes” in the Execution Analyzer view and configure the debug platform as follows:

debug config

Let’s build the code once more.

image

Now open the “Record and Analyze” window in Enterprise Architect.

image

In the “Record and Analyze” toolbar hit the Recording button – now a Sequence Diagram will be recorded in the selected package.

image

In the next screen specify Track instances – and type in Accounts.Account

image

The result is a Sequence Diagram that is not perfect, because there are three swimlanes and not two. But it is easier to read than the other alternative with only one swimlane.

image

Of course for this sample the perfect version should look like this:

image

If you start recording from the execution analyzer window with the debug command you still get the older viewer with only one swimlane not taking account any instances.

image

image

So still not perfect, but one can clearly see that a lot happened and that Enterprise Architect has been and will be improved in this area.

Waiting for your comments!

6 comments on “Tutorial – NUnit and Sequence Diagram Recording in Enterprise Architect 9.3

  1. Hello!

    We are trying to get running the sequence diagram recording with an NUnit-project. But we are not very successful doing so.
    Do you have a tutorial or any hints for us?

    Thanks.
    Karsten.

  2. Pingback: Enterprise Architect – Auto generating a sequence diagram from code | LieberLieber Software TeamBlog

  3. Pingback: Build Embedded Code from Enterprise Architect | LieberLieber Software TeamBlog

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>