Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting system properties when using junitPlatform

I could not find out how to set system properties when executing JUnit 5 tests using Gradle. The standard test task could be configured as follows:

test {
     systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', 'warn'
}

However, the junitPlatform task seem to not have such an option.

like image 475
Jan Schaefer Avatar asked Dec 26 '16 12:12

Jan Schaefer


People also ask

Where do JUnit platform properties go?

The JUnit Platform configuration file: a file named junit-platform. properties in the root of the class path that follows the syntax rules for a Java Properties file. Therefore you could create a common project with your junit-platform. properties and add this project into the classpath for each of your projects.

How do I run a JUnit 5 test in Maven?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.

Which annotation of JUnit 5 you will use to clean up the data or to perform an action after each test method?

@AfterAll is used to signal that the annotated method should be executed after all tests in the current test class. Note that to execute a method after each test, we can use @AfterEach annotation.


1 Answers

Update:

Please note that the junit-platform-gradle-plugin developed by the JUnit Team was deprecated in JUnit Platform 1.2 and discontinued in 1.3. Please switch to Gradle’s standard test task in Gradle 4.6 or higher. Details here.


As I mentioned here, if you are still using the obsolete junit-platform-gradle-plugin you can set system properties like this:

afterEvaluate {
    def junitPlatformTestTask = tasks.getByName('junitPlatformTest')

    junitPlatformTestTask.systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', 'warn'
}
like image 61
Sam Brannen Avatar answered Oct 27 '22 04:10

Sam Brannen