i am using gradle 3.5
and Unit 5 (jupiter)
.
i wish to pass System property to my tests, in order to configure the test
i am running the test using this command gradle test -Denv=envFile1
here is my grade file :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4' //JUnit 5
}
}
repositories {
mavenCentral()
}
ext.versionJunitPlatform = '1.0.0-M4'
ext.versionJunitJupiter = '5.0.0-M4'
ext.versionLog4j = '1.2.17'
ext.versionRestAssured = '2.9.0'
ext.versionRestAssuredJsonValid = '3.0.2'
ext.versionHamcrest = '1.3'
ext.versionJacksonDatabind = '2.9.0.pr2'
ext.versionSeleniumJava = '3.3.1'
test.systemProperties System.properties
dependencies {
compile group: 'log4j' , name: 'log4j' , version: "$versionLog4j" //Log4j
compile group: 'com.jayway.restassured' , name: 'rest-assured' , version: "$versionRestAssured" //Rest Assure
compile group: 'io.rest-assured' , name: 'json-schema-validator' , version: "$versionRestAssuredJsonValid" //Rest Assure schema validation
compile group: 'org.hamcrest' , name: 'hamcrest-all' , version: "$versionHamcrest" //Rest Assure assertion
compile group: 'com.fasterxml.jackson.core' , name: 'jackson-databind' , version: "$versionJacksonDatabind" //Serilize/Deserialize Request/Response objects
compile group: 'org.seleniumhq.selenium' , name: 'selenium-java' , version: "$versionSeleniumJava" //Selenium core, E2E testing
testCompile group: 'org.junit.jupiter' , name: 'junit-jupiter-api' , version: "$versionJunitJupiter"
testRuntime group: 'org.junit.jupiter' , name: 'junit-jupiter-engine' , version: "$versionJunitJupiter"
}
Here is my test:
package com.somecompany.someProject.tests;
import org.junit.jupiter.api.Test;
public class AaTest {
@Test
public void a() {
System.out.println("a test: " + System.getProperty("env"));
}
}
This is the output i get
gradle test -Denv=envName
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:junitPlatformTest
a test: null
thank you
shay
Aucun commentaire:
Enregistrer un commentaire