jeudi 2 novembre 2017

How to print wrong results in JUnit?

I'm reading this JUnit tutorial, where this example is reported:

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class MyTests {

    @Test
    public void multiplicationOfZeroIntegersShouldReturnZero() {
        MyClass tester = new MyClass(); // MyClass is tested

        // assert statements
        assertEquals("10 x 0 must be 0", 0, tester.multiply(10, 0));
        assertEquals("0 x 10 must be 0", 0, tester.multiply(0, 10));
        assertEquals("0 x 0 must be 0", 0, tester.multiply(0, 0));
    }
}

Now, my question is: in case the test fails, how do I print the (wrong) returned result? Something like:

        assertEquals("0 x 0 must be 0, instead got"+tester.multiply(0, 0), 0, tester.multiply(0, 0));

Aucun commentaire:

Enregistrer un commentaire