1

I have a test that does a cycle to run the same test but with different inputs. The problem is that when one assert fails, then the test stops, and it is marked as if one test failed.

Here is the code:

@Test public void test1() throws JsonProcessingException { this.bookingsTest(Product.ONE); } @Test public void test2() throws JsonProcessingException { this.bookingsTest(Product.TWO); } public <B extends Sale> void bookingsTest(Product product) { List<Booking> bookings = this.prodConnector.getBookings(product, 100); bookings.stream().map(Booking::getBookingId).forEach((bookingId) -> { this.bookingTest(bookingId); }); } public <B extends Sale> void bookingTest(String bookingId) { ... // Do some assert: Assert.assertEquals("XXX", "XXX"); } 

In that case, the methods test1 and test2, execute as two different tests, but inside them, I do a cycle to check some stuff on every item that is returned by the collection. But what I want is to make that test on each item to be treated as a different one, so that if one fails, the others continue executing and I can see which one failed and how many failed over the total.

1
  • 3
    You possibly want to have a look on parametrized tests Commented Nov 3, 2015 at 21:37

1 Answer 1

1

what you described is parameterized testing. there is plenty of frameworks that may help you. they just have different simplicity to power ratio. just pick the one that fits your needs.

junit's native way is @Parameterized but it's very verbose. other junit plugins that you may find useful are zohhak or junit-dataprovider. if you are not enforced to use junit and/or plain java, you can try spock or testng.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'm going with @Parametrized, didn't know of that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.