Step by Step Manuel how to create tests for EDMs - CDE-GMA/UIC.net-mono.c-sharp GitHub Wiki
Set up EDMs Blackbox tests:
Go to the Folder Tests in the UIC Solution and create a New NUnit Project for your tests or a Class in an existing Project
Copy all Tests, Setup and Teardown from the OveralllEDMTest.cs Class and paste it into your knew created Class
Be careful not to change your Class name or the namespace
Some Tests are specific to FakeEdm.cs and need to be modified bevor they are going to run for your new Class (example: HandleCommandTrueTest)
Import all the required usings
Change in the function SetUp() the expected Uri name and EDM (only EDMs build with the InterfaceEmbeddedDriverModule can run all tests otherwise just delete the Tests that aren’t implemented)
Run the Test
ether by right clicking in a test and running it (Ctrl+R, T)
or by running it over the Test Explorer by accessing it with the Test->Windows->Test Explorer (Ctrl+E, T)
Creating a new test:
After you created a new Test-Class and followed all the steps in “Set up EDMs Blackbox tests” you know have a Class to create new tests.
Write a new public void function with the [Test] Annotations/Attribute over it. This allows the Framework to understand that this function should be treated like a test.
Adding a Category to the test makes it easier to be overviewed in the future
Example Annotations/Attribute [Category("EDM")]
Writing the test, you should always follow the AAA system:
Arrange (Prepare all needed Inputs (Mocks) and Classes)
Act (Run the test on the function)
Assert (Compare your expected results with the real ones)
The Framework provides Assert capability
Examples for Whitebox tests:
HandleCommandTrueTest() or HandleCommandFalseTest() in the Class “OveralllEDMTest.cs” (This tests are specifically made for the FakeEdm.cs Class and won’t successfully run on other EDMs)
Creating a Test to run multiple times with multiple inputs:
The steps are the same as in “Creating a new test” with two difference
Instead of using the Annotations/Attribute [Test] the [TestCase(…)] is needed
The second difference is the function, as you have to create a function that accepts parameters (example: public void test(int i, string s)
Depending on the amount of [TestCase(…)]’s used the tests is going to be run multiple times with the given parameters (example: IsRunningTest(int x, bool expected) in the Class “OveralllEDMTest.cs”)
Mocking:
The Framework used is Moq, because of this only Interfaces are able to be mocked
Two steps are mostly needed for mocking:
Choose the Interface that is going to be Mocked and create a variable (example: var name = new Mock();)
Setup all needed returns for the Interface. This allows if the mocked function is being called to return a specific value (example: MockingDatapointDefinition in the Class “OveralllEDMTest.cs”)
To provide the mocked object to a function it is needed to be called with Object (example: Function(mocked.Object))