M
M
maxvinogradov2021-08-24 16:04:43
Java
maxvinogradov, 2021-08-24 16:04:43

Service testing, is it possible to create a separate class to store test objects or is it bad practice?

This is new for me.
When testing the service, the idea arose to create a separate TestData class and throw all objects and collections there (but make them unmodifiable, and objects final ). It's like an alternative to destroying and creating objects in @BeforeEach in the service test class. All the same, these objects do not change anywhere in the service.
Is it good practice to do this?
Or do you need to specifically prescribe objects in the class and re-create each time?

I will be very grateful to you for the answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-08-24
@maxvinogradov

Could be so.
I've seen some guys write DSL for testing purposes. (Like: User user = ObjectFather.getDefaultUser().with ... .please())
Well, I prefer storing test data as jasons: jasons are easy to store, easy to view, easy to convert to an object.

V
VictorZZZZ, 2021-09-02
@VictorZZZZ

If your test data spans 1000 rows. So why not)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question