JUnit 是否支持用于测试的属性文件? [英] Does JUnit support properties files for tests?

查看:18
本文介绍了JUnit 是否支持用于测试的属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要在各种不同的登台环境中运行的 JUnit 测试.每个环境都有不同的登录凭据或特定于该环境的其他方面.我的计划是将环境变量传递给 VM 以指示要使用的环境.然后使用该变量从属性文件中读取.

I have JUnit tests that need to run in various different staging environments. Each of the environments have different login credentials or other aspects that are specific to that environment. My plan is to pass an environment variable into the VM to indicate which environment to use. Then use that var to read from a properties file.

JUnit 是否有任何内置功能来读取 .properties 文件?

Does JUnit have any build in capabilities to read a .properties file?

推荐答案

java 内置了读取 .properties 文件的功能,而 JUnit 内置了在执行测试套件之前运行设置代码的功能.

java has built in capabilities to read a .properties file and JUnit has built in capabilities to run setup code before executing a test suite.

java读取属性:

Properties p = new Properties();
p.load(new FileReader(new File("config.properties")));

junit 启动文档

把这两个放在一起,你应该有你需要的.

put those 2 together and you should have what you need.

这篇关于JUnit 是否支持用于测试的属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆