mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Long test execution because of DirtiesContext #132

Closed simasch closed 1 year ago

simasch commented 1 year ago

Is DirtiesContext necessary because it slows down the whole test execution as the context cache is bypassed?

Currently it's configured on the AbstractKaribuTest

@DirtiesContext
@SpringBootTest
public abstract class AbstractKaribuTest {

IMO it would be better to let the developer decide.

mvysny commented 1 year ago

True. But what about Spring novices that just want the thing to work?

Maybe we remove @DirtiesContext from AbstractKaribuTest and add it to, say,

@DirtiesContext
public abstract class DirtiesContextKaribuTest extends AbstractKaribuTest {
}

? Then I'd document for Spring novices to extend from DirtiesContextKaribuTest, while experienced Spring devs would extend AbstractKaribuTest and configure things themselves.

What do you think @simasch ?

simasch commented 1 year ago

That's a good idea.

But what's the reason for DirtiesContext in KaribuTesting?

mvysny commented 1 year ago

Since Karibu is supposed to also support unit-testing, I thought that having a clean state of Spring-injectable stuff would make tests more reproducible - kinda always starting from a clean state. But then again, Karibu can be also used for system-testing where you have the entire app bootstrapped, database and all, and you click navmenu to navigate throughout the app, click buttons to open editor dialogs, etc, and in that sense maybe @DirtiesContext makes zero sense... :thinking: Just thinking out loud here, trying to imperfectly describe the idea and use-cases of Karibu.

What's your experience please? Could you describe your use-case where @DirtiesContext doesn't make much sense?

simasch commented 1 year ago

It's a tradeoff. I try never to use @DirtiesContext to speed up the test execution. That's a nice video why: https://www.youtube.com/watch?v=c-GV2PxymoY

The test must work on their own no matter what the state of the database is. And I mostly don't have unit tests because most of my apps use a database, and without the database, the tests are not useful.

mvysny commented 1 year ago

True, makes sense. I'll do the change.

mvysny commented 1 year ago

Eh, sorry @simasch but I can't find the AbstractKaribuTest class in Karibu. I can see AbstractSpringTest but that's internal to the testing of the Karibu itself. Could you please double-check the name of the class?

simasch commented 1 year ago

Hi @mvysny I'm so sorry but the AbstractKaribuTest is our own class. Probably it was copied from an example where you use DirtiesContext.

I'll close that issue but thanks for the discussion