BlueM.DLLAdapterTest: Difference between revisions

From BlueM
Jump to navigation Jump to search
(add section about reference to nunit.framework and change recommendation to install the msi)
(Add info on test datasets)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{BlueM_nav}}
{{BlueM.Sim_nav}}
'''BlueM.DLLAdapterTest''' is an assembly for running unit tests for [[BlueM.Sim]] and [[BlueM.DLLAdapter]] using [http://nunit.org NUnit].
'''BlueM.DLLAdapterTest''' is an assembly for running unit tests for [[BlueM.Sim]] and [[BlueM.DLLAdapter]] within Visual Studio.


==Installing NUnit==
==Getting the test datasets==
[[File:NUnit_reference.png|thumb|right|200px|Reference to nunit.framework]]
The test datasets used by the unit tests are available here: https://github.com/bluemodel/BlueM.Datasets/tree/master/BlueM/TESTS
To run the tests, you need to first install NUnit. Currently only NUnit version 2 is supported. The simplest way is to download the msi-package (NUnit-2.6.4.msi) and install it on your computer.


In Visual Studio, make sure that the reference to <code>nunit.framework</code> in the assembly IHWB.DLLAdapterTest has been found (no warning triangle). Otherwise, you may have to remove and re-add the reference.<br clear="both"/>
This folder needs to be copied to <code>BlueM.DLLAdapter\BlueM.DllAdapterTest\TESTS</code> in order for the tests to work. This may be solved differently in future, see [https://github.com/bluemodel/BlueM.DLLAdapter/issues/10 #10]


==Running tests==
==Running tests==
[[File:NUnit.png|thumb|right|500px|Screenshot of NUnit with the test assembly loaded]]
[[File:BlueM.DLLAdapterTest_VS2019.png|thumb|right]]
Once you have NUnit, execute <code>nunit-x86.exe</code> and then click on ''File - Open Project'' and and select the file <code>IHWB.BlueM.DLLAdapterTest.dll</code>, which you should have gotten by compiling the BlueM.DLLAdapterTest assembly. This will cause all tests contained in the assembly to be listed in the left pane (see screenshot).
In Visual Studio, open the ''Test Explorer'', which will autodetect the tests defined within the loaded project.  
 
You can now run all or only selected tests. Ideally, all tests should pass.<br clear="both"/>
 
==Debugging tests==
[[File:NUnit_solutionexplorer.png|right|200px]]
[[File:NUnit_debugging.png|thumb|right|500px|Screenshot of the Visual Studio property pages of NUnit]]
It is also possible to debug tests from within Visual Studio.
 
First, make sure that nunit.exe is is listed as a project in the solution explorer. If it isn't, add it or check out from the [[BlueM.Sim_Development|Meta repository]] to get a solution file already containing NUnit.
 
Then edit the properties of the nunit.exe-project and make sure that the ''Command'' and ''Working Directory'' are set correctly (see screenshot).
 
To start NUnit with debugging functionality, right-click on nunit.exe in the solution explorer and select ''Debug -  Start new instance''. The NUnit GUI will appear, where you need to load <code>IHWB.BlueM.DLLAdapterTest.dll</code> as the project and can then run the tests with debugging enabled.
 
 
 


Note that the assembly BlueM.DLLAdapterTest containing the unit tests is only configured to automatically build in the Debug configuration, so either use this configuration or, to test the Release version, force a build of BlueM.DLLAdapterTest by right-clicking it in the solution explorer.


You can then run all or just individual tests. To debug tests, right-click on a test and select ''Debug Test'' or choose ''Debug All Tests'' from the main ''Test'' menu.


==Writing tests==
To write new tests, copy the pattern of the already existing tests or read the documentation here: https://docs.microsoft.com/en-us/visualstudio/test/unit-test-your-code?view=vs-2019


[[Category:BlueM.Sim Development]]
[[Category:BlueM.Sim Development]]

Latest revision as of 01:47, 4 March 2023

BlueM_icon.png BlueM.Sim | Download | Application | Theory | Development

BlueM.DLLAdapterTest is an assembly for running unit tests for BlueM.Sim and BlueM.DLLAdapter within Visual Studio.

Getting the test datasets

The test datasets used by the unit tests are available here: https://github.com/bluemodel/BlueM.Datasets/tree/master/BlueM/TESTS

This folder needs to be copied to BlueM.DLLAdapter\BlueM.DllAdapterTest\TESTS in order for the tests to work. This may be solved differently in future, see #10

Running tests

BlueM.DLLAdapterTest VS2019.png

In Visual Studio, open the Test Explorer, which will autodetect the tests defined within the loaded project.

Note that the assembly BlueM.DLLAdapterTest containing the unit tests is only configured to automatically build in the Debug configuration, so either use this configuration or, to test the Release version, force a build of BlueM.DLLAdapterTest by right-clicking it in the solution explorer.

You can then run all or just individual tests. To debug tests, right-click on a test and select Debug Test or choose Debug All Tests from the main Test menu.

Writing tests

To write new tests, copy the pattern of the already existing tests or read the documentation here: https://docs.microsoft.com/en-us/visualstudio/test/unit-test-your-code?view=vs-2019