我有一个包含junit测试的Java项目,它需要通过Jenkins在不同的测试环境(Dev,Staging等)上运行。Maven,Jenkins - 如何构建项目到不同的测试环境?
如何将项目的构建安装到不同的环境以及如何将URL,用户名和密码传递给maven?
我可以使用maven 3配置文件从属性文件中读取环境URL,用户名和密码吗?
编辑:我已经添加了配置文件到项目POM:
<profiles>
<profile>
<id>Integration</id>
</profile>
<profile>
<id>Staging</id>
</profile>
<profile>
<id>PP1</id>
</profile>
<profile>
<id>PP2</id>
</profile>
<profile>
<id>PP3</id>
</profile>
</profiles>
如何通过URL,用户名和密码,这些配置文件?
目前的测试是从属性文件获取测试环境的详细信息:
public class BoGeneralTest extends TestCase {
protected WebDriver driver;
protected BoHomePage boHomePage;
protected static Properties systemProps;
String url = systemProps.getProperty("Url");
String username = systemProps.getProperty("Username");
String password = systemProps.getProperty("Password");
int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
static {
systemProps = new Properties();
try {
systemProps.load(new FileReader(new File("src/test/resources/environment.properties")));
} catch (Exception e) {
e.printStackTrace();
}
}
编辑2:
在测试运行器类实现的变化:
public class BoGeneralTest extends TestCase {
protected WebDriver driver;
protected BoHomePage boHomePage;
protected static Properties systemProps;
String url = systemProps.getProperty("Url");
String username = systemProps.getProperty("Username");
String password = systemProps.getProperty("Password");
int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
String regUsername = RandomStringUtils.randomAlphabetic(5);
final static String appConfigPath = System.getProperty("appConfig");
static {
systemProps = new Properties();
try {
systemProps.load(new FileReader(new File(appConfigPath)));
} catch (Exception e) {
e.printStackTrace();
}
}
谢谢!这非常有帮助。我正在努力改变加载属性文件的代码。任何建议将受到欢迎:弓。 – 2013-03-19 13:32:25
@AtanasKanchev查看[本教程的加载属性](http://docs.oracle.com/javase/tutorial/essential/environment/properties.html)了解一些指针。我希望有所帮助。 :-) – Jonathan 2013-03-19 14:38:31
谢谢乔纳森我已经实现了你的方法,它工作正常。虽然有一个缺点 - 现在单个测试不能单独运行,因为他们期望从maven接收appConfig,并且我得到NullPointerException – 2013-03-19 18:08:49