After this training session:
- you know how a test class looks like
- you know how you create a test method within a test class
- you know what are assertions and how they're used
- use full qualified type identifier for items in namespaces
- you know, where you find information for writing test functions
- you know where you find guidelines and tips for writing tests
-
Open the file
Test_Valve.stin the foldertestHere you can see a template for a test class. It's marked with the pragma
{TestFixture}Tip: You can filter the files in the Explorer:
More information you'll find here
AxUnit support not just test classes. It supports also test functions
-
Insert a test method. By entering
tethe snippettest-methodwill be proposed. And press enterTest methods will be marked with the pragma
{Test} -
Change the name of the method to
Test_Open_valve_and_Expect_IsOpen_TrueRecommendations for writing tests, you'll find here
-
In the next step we select our class we want to test. Therefore we declare the variable v in the VAR section
VAR PRIVATE v : Simatic.Ax.Tutorial.Valve; END_VARIn this case we use the full qualified name for the Valve class. This is an alternative to
USING Simatic.Ax.Tutorial;. -
To implement the test itself, we modify the method
MyTestMethodin this way:{Test} METHOD PUBLIC Test_Open_valve_and_Expect_IsOpen_True v.Open(); AxUnit.Assert.Equal(actual := v.IsOpen(), expected := TRUE); END_METHODExplanation:
-
The method
v.Open()calls the method Open of the class valve. In this case we expect, that the methodIsOpen()returns the valueTRUE -
The expression
Equal(actual := v.IsOpen(), expected := TRUE);contains the assertionEqualwhich check if the returned value ofIsOpen()equalsTRUE.Further assertions are:
- NotEqual
- LessThan
- GreaterThan
More information regarding testing, you'll find here
-
Goal reached? Check yourself...
- you know how a test class looks like ✔
- you know how you create a test method within a test class ✔
- you know what are assertions and how they're used ✔
- use full qualified type identifier for items in namespaces ✔
- you know, where you find information for writing test functions ✔
- you know where you find guidelines and tips for writing tests ✔



