Saturday 16 December 2017

TrafficControl: Testing Asserts

Asserts are used to ensure that events that should never happen will never happen.

I've created a test case, where the program will try to add the same train to a station twice. If that happens, it would be a sign that the program has totally lost control of the network.
The program adds a train to a station. After that, it tries to add the same train to the station again. The expected result shall be an Assert.
When the code tries to add the same train again, the code asserts:

After this dialog, the test sequence stops and the remaining test cases are not run.

I found a workaround in a StackOverflow thread. A message handler will acknowledge the Assert message in the test case and the test suite can continue:
A message handler is specified before the expected Assert. It acknowledges the assert, without crashing the test.




No comments:

Post a Comment