Skip to main content
added 6 characters in body
Source Link
Martijn Pieters
  • 14.7k
  • 10
  • 60
  • 59

Another reason why I think, that multiple assersasserts in one method is not a bad thing is described in following code:

class Service { Result process(); } class Result { Inner inner; } class Inner { int number; } 

In my test I simply want to test that service.process() returns the correct number in Inner class instanceinstances.

Instead of testing...

@Test public void test() { Result res = service.process(); if ( res != null && res.getInner() != null ) Assert.assertEquals( ..., res.getInner() ); } 

I'm doing

@Test public void test() { Result res = service.process(); Assert.notNull(res); Assert.notNull(res.getInner()); Assert.assertEquals( ..., res.getInner() ); } 

Another reason why I think, that multiple assers in one method is not a bad thing is described in following code:

class Service { Result process(); } class Result { Inner inner; } class Inner { int number; } 

In my test I simply want to test that service.process() returns correct number in Inner class instance.

Instead of testing...

@Test public void test() { Result res = service.process(); if ( res != null && res.getInner() != null ) Assert.assertEquals( ..., res.getInner() ); } 

I'm doing

@Test public void test() { Result res = service.process(); Assert.notNull(res); Assert.notNull(res.getInner()); Assert.assertEquals( ..., res.getInner() ); } 

Another reason why I think, that multiple asserts in one method is not a bad thing is described in following code:

class Service { Result process(); } class Result { Inner inner; } class Inner { int number; } 

In my test I simply want to test that service.process() returns the correct number in Inner class instances.

Instead of testing...

@Test public void test() { Result res = service.process(); if ( res != null && res.getInner() != null ) Assert.assertEquals( ..., res.getInner() ); } 

I'm doing

@Test public void test() { Result res = service.process(); Assert.notNull(res); Assert.notNull(res.getInner()); Assert.assertEquals( ..., res.getInner() ); } 
Source Link
Betlista
  • 349
  • 3
  • 10

Another reason why I think, that multiple assers in one method is not a bad thing is described in following code:

class Service { Result process(); } class Result { Inner inner; } class Inner { int number; } 

In my test I simply want to test that service.process() returns correct number in Inner class instance.

Instead of testing...

@Test public void test() { Result res = service.process(); if ( res != null && res.getInner() != null ) Assert.assertEquals( ..., res.getInner() ); } 

I'm doing

@Test public void test() { Result res = service.process(); Assert.notNull(res); Assert.notNull(res.getInner()); Assert.assertEquals( ..., res.getInner() ); } 
Post Made Community Wiki by Betlista