我有一个使用Java编写、利用TestNg并使用gradle构建的测试框架。我想在命令行传递一个“环境”参数,它将被用于Environment类中,以定义特定环境下的域和服务器值。尽管查阅了Gradle文档和多个论坛讨论此问题,但我仍无法将该参数作为系统属性传递给框架。我已经试过从“test”任务和“debug”任务两方面实现,但都没有成功。任务中的“println”语句表明-Denv参数已被Gradle捕获,但我试图将其添加到测试框架的System属性中却失败了。
执行结果显示出现了空引用,其中environmentName被设置为null。
请问有人能够找出我的错误吗?
命令行
执行结果显示出现了空引用,其中environmentName被设置为null。
请问有人能够找出我的错误吗?
命令行
.\gradlew debug -Denv=production
build.gradle
test {
def environment = System.properties["env"]
println environment
systemProperties = System.getProperties()
systemProperties['env'] = environment
useTestNG()
}
task debug(type: Test) {
// def environment = System.properties["env"]
// println environment
// systemProperties = System.getProperties()
// systemProperties['env'] = environment
def groupsToInclude = []
def groupsToExclude = []
groupsToInclude.add('under_development')
useTestNG() {
groupsToInclude.each { String group -> includeGroups group }
groupsToExclude.each { String group -> excludeGroups group }
}
}
Java类
import com.sun.javafx.runtime.SystemProperties;
public class Environment {
private static EnvironmentDefinition environment;
private Environment() {
}
public static EnvironmentDefinition getInstance() {
if (environment == null) {
String environmentName = SystemProperties.getProperty("env");
// environmentName = environmentName == null ? "production" : environmentName;
switch (environmentName) {
default:
Environment.environment = ProductionEnvironment.getInstance();
}
}
return environment;
}
}
exec
之前 -echo "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.launcher.GradleMain "$@"
。下一行应该是exec。报告输出。 - Prashant