I have a simple JUnit test in Eclipse.
public class HelloTest extends TestCase {
CalculatorEngine ce;
public HelloTest(String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
ce = new CalculatorEngine();
}
@Override
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
super.tearDown();
ce = null;
}
public void test1() {
assertTrue(ce.doCalculation("1+5").equals("2"));
}
}
The test fails because 1+5 does not equal 2. If I change 1+5 to 1+1 the test is successful.
How can I get some feedback/output from JUnit to determine what the result was when the test failed? In other words is there any way I can find out that ce.doCalculation(“1+5”) returned 6 instead of 2?
You could use the assertEquals method for your check
(available to check/compare most types – have a look at the API documentation).