Cómo obtener comentarios sobre JUnit Testing en Eclipse

I have a simple JUnit test in Eclipse.

public class HelloTest extends TestCase {
    CalculatorEngine ce;

    public HelloTest(String name) {

    protected void setUp() throws Exception {
        ce = new CalculatorEngine();

    protected void tearDown() throws Exception {
        // TODO Auto-generated method stub
        ce = null;

    public void test1() {

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?

preguntado el 30 de enero de 12 a las 19:01

2 Respuestas

Podrías usar el asertEquals 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).

Respondido el 31 de enero de 12 a las 00:01

That's correct, thanks! I actually solved it myself and was in the process of posting the answer when your answer came up. It will let me mark it as correct in 5 minutes. - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

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

assertThat(1, is(2))


assertThat(1, is(not(2))

Respondido el 31 de enero de 12 a las 00:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.