How to write a failing test in this case?

1k Views Asked by At

I want to test some simple programs with evosuite in intellij and I want some test be failed . I was generated test with evosuite and test_cases are built. But when i test them with junit after, all of them are passed!

How can I fail some test in program? This is my simple program that I add "while(true)" to be wrong:

While(true) 
      int a=8;
      int b=2;
      a=b; 
1

There are 1 best solutions below

3
On

use assertions, abort() method, and throw exceptions as needed.

imagine you have a method which is expected to return 2. here is how you can test it:

int a = yourmethod();
Assert.assertEquals(2, a);

if a certain condition should be satisfied:

if (condition) {
// Check something else
} else {
abort() // this method fails the test
}