-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Introduce a new set of test callbacks used right before and after test execution
- Loading branch information
Showing
9 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...n-tests/main/src/test/java/io/quarkus/it/main/QuarkusBeforeAndAfterTestCallbacksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class QuarkusBeforeAndAfterTestCallbacksTest { | ||
|
||
@BeforeEach | ||
@AfterEach | ||
public void ensureMissingSystemProperty() { | ||
assertNull(System.getProperty("quarkus.test.method")); | ||
} | ||
|
||
@Test | ||
public void actualTest() { | ||
assertEquals("actualTest", System.getProperty("quarkus.test.method")); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/src/test/java/io/quarkus/it/main/SystemPropertySetterAfterTestExecutionCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.it.main; | ||
|
||
import io.quarkus.test.junit.callback.QuarkusTestAfterTestExecutionCallback; | ||
import io.quarkus.test.junit.callback.QuarkusTestMethodContext; | ||
|
||
public class SystemPropertySetterAfterTestExecutionCallback implements QuarkusTestAfterTestExecutionCallback { | ||
|
||
@Override | ||
public void afterTestExecution(QuarkusTestMethodContext context) { | ||
System.clearProperty("quarkus.test.method"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ain/src/test/java/io/quarkus/it/main/SystemPropertySetterBeforeTestExecutionCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.it.main; | ||
|
||
import io.quarkus.test.junit.callback.QuarkusTestBeforeTestExecutionCallback; | ||
import io.quarkus.test.junit.callback.QuarkusTestMethodContext; | ||
|
||
public class SystemPropertySetterBeforeTestExecutionCallback implements QuarkusTestBeforeTestExecutionCallback { | ||
|
||
@Override | ||
public void beforeTestExecution(QuarkusTestMethodContext context) { | ||
System.setProperty("quarkus.test.method", context.getTestMethod().getName()); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...es/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterTestExecutionCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.it.main.SystemPropertySetterAfterTestExecutionCallback |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeTestExecutionCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.it.main.SystemPropertySetterBeforeTestExecutionCallback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestAfterTestExecutionCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.test.junit.callback; | ||
|
||
/** | ||
* Can be implemented by classes that shall be called immediately after a test method in a {@code @QuarkusTest}. | ||
* These callbacks run before {@link QuarkusTestAfterEachCallback} callbacks and are usually accompanied by | ||
* {@link QuarkusTestBeforeTestExecutionCallback}. | ||
* <p> | ||
* The implementing class has to be {@linkplain java.util.ServiceLoader deployed as service provider on the class path}. | ||
*/ | ||
public interface QuarkusTestAfterTestExecutionCallback { | ||
|
||
void afterTestExecution(QuarkusTestMethodContext context); | ||
} |
13 changes: 13 additions & 0 deletions
13
.../src/main/java/io/quarkus/test/junit/callback/QuarkusTestBeforeTestExecutionCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.test.junit.callback; | ||
|
||
/** | ||
* Can be implemented by classes that shall be called right before a test method in a {@code @QuarkusTest}. | ||
* These callbacks run after {@link QuarkusTestBeforeEachCallback} callbacks and are usually accompanied by | ||
* {@link QuarkusTestAfterTestExecutionCallback}. | ||
* <p> | ||
* The implementing class has to be {@linkplain java.util.ServiceLoader deployed as service provider on the class path}. | ||
*/ | ||
public interface QuarkusTestBeforeTestExecutionCallback { | ||
|
||
void beforeTestExecution(QuarkusTestMethodContext context); | ||
} |