How to get feedback on JUnit Testing in Eclipse

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?

Upvotes: 0

Views: 239

Answers (2)

Martin
Martin

Reputation: 7149

You can also write more descriptive tests using the assertThat api e.g:-

assertThat(1, is(2))

or

assertThat(1, is(not(2))

Upvotes: 1

FrVaBe
FrVaBe

Reputation: 49341

You could use the assertEquals method for your check

assertEquals("Unexpected result!", 2, ce.doCalculation("1+5"));

(available to check/compare most types - have a look at the API documentation).

Upvotes: 3

Related Questions