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.
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 .
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.
Now it should look like this:
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.
Choose C# and point it to the C:\Source\Accounts\src\Accounts directory!
After the import the project browser should look like this:
Preparing the Execution Analyzer
Click on the before created Package (here “Classes”) and choose Execution Analyzer.
The following message should show up – just click “Yes”.
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
Let’s build from inside Enterprise Architect
Right click on the package and choose build.
In the output window you should see something like below.
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:
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
“C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console-x86.exe” AccountsTest\bin\x86\Debug\AccountsTest.dll
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”.
Next you need to open the testing window!
Navigate to the class AccountTest in Project Browser
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
In the Execution Analyzer.
* Call Build and then
* Call Test
Go back to the “Testing” window with AccountTest selected in the Project Browser.
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:
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.
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:
Let’s build the code once more.
Now open the “Record and Analyze” window in Enterprise Architect.
In the “Record and Analyze” toolbar hit the Recording button – now a Sequence Diagram will be recorded in the selected package.
In the next screen specify Track instances – and type in Accounts.Account
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.
Of course for this sample the perfect version should look like this:
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.
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!