0

I have an object under test and want to verify it was configured correctly by testing the return values of methods. Is there a way to do this without creating one test per method?

I'm imagining something like:

assertThat(obj).fieldIs(Obj::methodA, "value1").fieldIs(Obj::methodB, "value1");
gph
  • 1,045
  • 8
  • 25
  • 3
    Does this answer your question? [JUnit5: How to assert several properties of an object with a single assert call?](https://stackoverflow.com/questions/57476351/junit5-how-to-assert-several-properties-of-an-object-with-a-single-assert-call) – Stefano Cordio Dec 06 '22 at 22:08

1 Answers1

1

You can make a big test method that tests all fields of the object are as they should be, you aren't limited to one assertSomething() per method. Example:

@Test
public void testFields() {
    Object someObj = theObjInstance;
    assertEquals("value1", someObj.methodA());
    assertEquals("value2", someObj.methodB());
    // ...
}
0x150
  • 589
  • 2
  • 11