我有一个testng类,它测试一个类,然后从类路径加载属性。当我运行maven安装我得到一个错误提及文件未找到。它不能找到属性文件,虽然我在src/test/resources
。如何解决这个问题?加载属性文件为maven-surefire-plugin
的Java代码具有尝试加载属性文件Properties props = JobUtils .loadProperties("x.properties");
构造我的Maven配置:
<plugin>
<groupId>org.apache.maven.plugins
<artifactId>maven-surefire-plugin
<version>2.5
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
有:
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
</testResources>
</build>
我也有这个x.properties
在src/test/resource
运行TestSuite的堆栈跟踪是:
java.io.FileNotFoundException: x.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at java.io.FileInputStream.(FileInputStream.java:66)
另请注意,测试类我尝试实例化此Java代码并进行测试。
您能否提供更多信息,因为它不足以帮助您? 'mvn test'能正常工作吗?属性文件是某种环境/配置文件配置的一部分吗?你能发布试图加载属性文件的堆栈跟踪和代码吗? – Augusto
java代码有一个构造函数,它尝试加载属性文件属性props = JobUtils \t \t \t \t .loadProperties(“x.properties”);我的Maven配置 org.apache.maven.plugins Maven的万无一失,插件 2。5 <结构> 假 配置> –
Siva
与构建 的src /测试/资源 假 testResource> testResources> 另外我在src/test/resource中有这个x.properties堆栈跟踪运行TestSuite java.io.FileNotFoundException:x.properties(系统不能fin d指定的文件) 位于java.io.FileInputStream.open(本机方法) 位于java.io.FileInputStream。 (FileInputStream.java:106) at java.io.FileInputStream。 (FileInputStream.java:66) –
Siva