gph
gph

Reputation: 1359

Testing object method return values

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");

Upvotes: 0

Views: 42

Answers (1)

user13290159
user13290159

Reputation:

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());
    // ...
}

Upvotes: 1

Related Questions