我在运行以下代码时遇到问题:
I am having a problems running the following code:
configService.setMainConfig("src/test/resources/MainConfig.xml");
从 Junit @Before 方法中.
From within a Junit @Before method.
这是 Maven 构建其目标文件夹的方式吗?
Is this the way Maven builds out its target folder?
直接访问MainConfig.xml.src/test/resources 目录内容放置在您的 CLASSPATH 的根目录中.
Access MainConfig.xml directly. The src/test/resources directory contents are placed in the root of your CLASSPATH.
更准确地说:src/test/resources的内容被复制到target/test-classes中,所以如果你有以下项目结构:
More precisely: contents of src/test/resources are copied into target/test-classes, so if you have the following project structure:
.
└── src
└── test
├── java
│ └── foo
│ └── C.java
└── resources
├── a.xml
└── foo
└── b.xml
它将产生以下测试 CLASSPATH 内容:
It will result with the following test CLASSPATH contents:
/foo/C.class/a.xml/foo/b.xml要真正从 Java 源访问文件,请使用getClass().getResource("/MainConfig.xml").getFile().
To actually access the files from Java source, use
getClass().getResource("/MainConfig.xml").getFile().
这篇关于为什么我无法在使用 Maven 的 Junit 测试运行中访问 src/test/resources?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)