Testing Code Containing Infinite Loops

Question:
My source code contains an infinite loop? Is there a way to break out of the infinite loop while unit testing with VectorCAST?
Answer:
Probe Points are a great way test infinite loops.

We can insert a “break” into the code to force it to terminate after one iteration, or any number of iterations we choose.

Let us take a look at the number of ways we can do it.
  • In method 1; I want to only run the loop once. The easiest and quickest way is to put a break in at the end of the loop with my probe point.  
  • In method 2; I want to get a number of results, I can set a static count to run the loop 10 times and output certain private member variable values for each loop.
  • In method 3; I have declared some user code in the environment user code. My probe point will check the value of the user prefix user code and break when the conditions are right.


Article ID: 1509
Last updated: 2019-11-13
Revision: 2
VectorCAST -> C++ Unit Testing -> Testing Code Containing Infinite Loops
https://kb.vector.com/entry/1509/