dimanche 27 décembre 2015

TestNG test failure even if expected exception is specified

Im writing tests with TestNG framework. Everything works fine, except one test, when Im checking Service failure and Im expecting Exception class.

Here is my code:

@Test(expectedExceptions = BookNotFoundException.class)
    public void findBookFailureTest() throws BookNotFoundException{
        when(booksRepository.findOne(new Long(1))).thenReturn(book);

        booksService.findBook(new Long(67));    
    }

And here is test resut:

Results :

Failed tests:
findBookFailureTest(pl.library.services.BooksServiceImplTest): (..)

Tests run: 7, Failures: 1, Errors: 0, Skipped: 0

Why that test fails even if I specified that I expect that Exception?

Aucun commentaire:

Enregistrer un commentaire