eclipse-vertx / vertx-junit5

Testing Vert.x applications with JUnit 5
Apache License 2.0
44 stars 32 forks source link

RunTestOnContext for JUnit 5 #100

Closed DavideD closed 3 years ago

DavideD commented 3 years ago

There is this rule available for JUnit 4:

    @Rule
    public RunTestOnContext vertxContextRule = new RunTestOnContext();

It would be nice to have something similar for JUnit 5. Probably an extension.

jponge commented 3 years ago

Good idea @DavideD, would you like to try to contribute it?

DavideD commented 3 years ago

I can try but I might need some help. Can I copy the logic in Vert.x RunTestOnContext? It seems it delegates some things to the VertxUnitRunner, should I do something similar and call the methods in VertxExtension?

jponge commented 3 years ago

I think yes you can copy or take inspiration from what's been done there.

vietj commented 3 years ago

@DavideD any progress on this contribution?

DavideD commented 3 years ago

No, sorry. I didn't have time

tsegismont commented 3 years ago

jUnit5 has a mechanism for intercepting test method calls.

This could be used to get a Vert.x context then run the test on this context.

@jponge the jUnit5 documentation says checkpoints shouldn't be used on Vert.x threads. Can you explain why?

This could be a problem if running tests on a Vert.x context.

jponge commented 3 years ago

That might be a bad explanation in the docs then, can you please point me to the corresponding sentence?

tsegismont commented 3 years ago

https://vertx.io/docs/vertx-junit5/java/#_checkpoint_when_there_are_multiple_success_conditions

TIP: Checkpoints should be created only from the test case main thread, not from Vert.x asynchronous event callbacks.

jponge commented 3 years ago

Makes sense.

Checkpoints shall be created from the test main thread (e.g., when you enter a test method).

Then checkpoints shall be used from anywhere else (e.g., flagging from a callback).

This is because we had some users who created new checkpoints on the fly, like in the middle of a callback, but the main test context had already completed because it could not have anticipated that they would even exist.

tsegismont commented 3 years ago

Ok. Perhaps we should change the tip wording then, it is confusing.