Test Case Identifiers
When you make changes to a model and generate new test cases, you might want to be able to tell whether some of these test cases are the same as some of the test cases generated from a previous version of the model. To assist you in this task, Spec Explorer can compute a hash code for each test case from the sequence of action invocations that make up the test case.
You can use these hash codes as arguments to .Net attributes that will annotate generated tests. The following Cord configuration demonstrates the use of the TestMethodAttribute switch together with the $TestCaseHashCode$ variable, which refers to the hash code for the test case.
switch TestMethodAttribute =
"Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod, Microsoft.VisualStudio.TestTools.UnitTesting.TestProperty(\"id\", \"$TestCaseHashCode$\")";
In generated test cases in test code generation mode, the generated C# method has attributes such as the following.
[Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestProperty("id", "0x018d4744437ff3e9c8bbf3aacfbe7e5f2c")]
If you make changes to your model and regenerate test code, the hash codes for any test cases that contain the same sequence of action invocations will have the same hash code. The hash code does not guarantee the ability to identify test case equivalence at any deeper level of semantics. The hash codes are intended to help identify test cases that may be exactly the same as previously generated ones, and this process is most useful where you have made relatively small incremental changes to the test machines.
The hash code can also be used as part of the test case name by using the TestCaseName switch. By default, the identifier is based on the name of the action machine from which the suite is generated and the name of the state in which the test case starts.
The following Cord configuration code demonstrates the use of the TestCaseName switch together with the $MachineName$ and $TestCaseHashCode$ variables. The $MachineName$ variable refers to the name of the machine from which the test case was generated.
switch TestCaseName = "$MachineName$_$TestCaseHashCode$";
The test method containing each test case is now generated with the hash code appended to the machine name.
public void MyMachine_0x018d4744437ff3e9c8bbf3aacfbe7e5f2c() {
// Generated test case body.
}
For more information about the test code generation switches, see Test Code Generation Switches. For more information about the built-in variables, see SwitchClause.