Nirmal Nirmal - 1 year ago 152
Java Question

junit (eclipse) test neither fails nor passes

I am running the test in eclipse. The jar and test are properly written. I have made sure that it is not versioning error etc. After I run the test, the console (in eclipse) shows that the programs ran successfully and terminated but in junit test perspective, in eclipse, the red button becomes disabled but the "Rerun Test" still remains enabled. There is no failure trace neither do I see the green bar indicating test success. Any pointer in this will help.

import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ExampleTest{

public void setUp() throws Exception {

public static void setUpBeforeClass() throws Exception {

public void tearDown() throws Exception {

public static void tearDownAfterClass() throws Exception {

public void validityTest() {
String userInput = ValidatorCode.validateStr("validStr");
assertEquals("theValidValue", userInput);

Answer Source

Found a piece of code where System.exit(0)was being used to terminate execution. Junit doesn't like that, apparently. I replaced the System.exit(0) with return statement, it worked like a charm. Having solved this problem, my further question would be, what's the logic behind Junit not liking System.exit(0)? System.exit(0) indicates clean exit or smooth execution of process(sans anything alarming), well! shouldn't Junit like that then?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download