'Is there a better way to terminate a Java test or make it pass after executing the else statement? [closed]
Given this code:
int demo = test.size();
if (demo!=0){
//do something
}
else {
System.exit(0);
}
Is there a better way to terminate the test or make it pass after the else statement is executed instead of using System.exit(0);
Solution 1:[1]
The best answer for testing is to use an external library. JUnit is a very good option at your disposal, though you can feel free to use whatever you would prefer. For this specific code, you would probably want to use something like this:
public class Tester {
@Test public void test1() {
List<Whateverclass> test = //Whatever your code is
assertNotEmpty(test); //Credit to chrylis for this!
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
