mercredi 22 juillet 2020

Assert an Exception is Thrown in

I have this Junit test in my project

public class CalculatorBookingTest {

    private CalculatorBooking calculatorBooking;

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Before
    public void setUp() {
        calculatorBooking = new CalculatorBooking();
    }

    @Test
    public void shouldThrowAnException_When_InputIsNull() {
        calculatorBooking.calculate(null, null, 0, null);
        expectedException.expect(CalculationEngineException.class);
        expectedException.expectMessage("Error");
    }

}

but when I run the test, the Exception is Thrown but nevertheless the test fail

Aucun commentaire:

Enregistrer un commentaire