2

This answer specifically answer's my question

In Junit is there a way to make sure the code makes it past a certain point?

ex:

@Test(expect = SpecialException.class)
public void testMyCode() {
    essentialMethodThatCantBeMockedThatMayThrowSpecialException()

    // stuff

    actualMethodIAmTestingAndWillAlsoThrowSpecialException()
}

The main purpose is that I am doing a major refactor and if I can outfit my existing tests with something like an expect x number of assertions. Then that would make sure that my tests throw exceptions for the correct reasons and not the wrong reasons.

A good example of something that does this is Qunit which has a expect(numberOfAssertions) which will fail the test if that many assertions are not called.

I have been looking a long time for something like this in JUnit but I can't find it.

Community
  • 1
  • 1
dtracers
  • 1,534
  • 3
  • 17
  • 37

0 Answers0