lundi 14 août 2023

How to design a test case that creates a lot of business entities which attributes are used on the test conditions

I'm developing a test case, in Java with Junit Jupiter, that creates a lot of business objects which attributes are used on the test conditions.
The application being tested uses data persisted in some persistent unit, using the business objects, to create some kind of result. The result's data is tightly related to the business object attributes persisted.
The code looks lie this:

MyBusinessDto myBusinessDto = new MyBusinessDto();
MyOtherBusinessDto myOtherBusinessDto = new MyOtherBusinessDto();
...
YetAnotherBusinessDto yetAnotherBusinessDto = new YetAnotherBusinessDto();

//execution, where the business dto's are persisted on some system

PersistedSystemDto persistedSystemDto = getResult();

assertThat(persistedSystemDto.someAttr())
    .isEqualTo(myBusinessDto.anAttr());
assertThat(persistedSystemDto.someOtherAttr())
    .isEqualTo(myOtherBusinessDto.otherAttr());
...
assertThat(persistedSystemDto.yetAnotherAttr())
    .isEqualTo(yetAnotherBusinessDto.yetAnotherAttr());

The problem I see is on the business object creation. There are a lot of lines on the test's body just to create the business objects and it just does not feels right.
Is there a pattern or approach to deal with this king of scenarios?

Aucun commentaire:

Enregistrer un commentaire