mardi 2 octobre 2018

How can I ensure that a particular exception is thrown in JUnit5?

With JUnit4 you could e.g. just write:

@Test (expectedException = new UnsupportedOperationException()){...}

How is this possible in JUnit5? I tried this way, but I'm not sure if this is equal.

@Test
    public void testExpectedException() {
        Assertions.assertThrows(UnsupportedOperationException.class, () -> {
            Integer.parseInt("One");});

Aucun commentaire:

Enregistrer un commentaire