<i id='da5vU'><tr id='da5vU'><dt id='da5vU'><q id='da5vU'><span id='da5vU'><b id='da5vU'><form id='da5vU'><ins id='da5vU'></ins><ul id='da5vU'></ul><sub id='da5vU'></sub></form><legend id='da5vU'></legend><bdo id='da5vU'><pre id='da5vU'><center id='da5vU'></center></pre></bdo></b><th id='da5vU'></th></span></q></dt></tr></i><div id='da5vU'><tfoot id='da5vU'></tfoot><dl id='da5vU'><fieldset id='da5vU'></fieldset></dl></div>
    • <bdo id='da5vU'></bdo><ul id='da5vU'></ul>
    <tfoot id='da5vU'></tfoot>

      <legend id='da5vU'><style id='da5vU'><dir id='da5vU'><q id='da5vU'></q></dir></style></legend>

      <small id='da5vU'></small><noframes id='da5vU'>

    1. 为什么我无法在使用 Maven 的 Junit 测试运行中访问 src/test/resources?

      时间:2023-05-29
      • <tfoot id='dbTzt'></tfoot>
      • <i id='dbTzt'><tr id='dbTzt'><dt id='dbTzt'><q id='dbTzt'><span id='dbTzt'><b id='dbTzt'><form id='dbTzt'><ins id='dbTzt'></ins><ul id='dbTzt'></ul><sub id='dbTzt'></sub></form><legend id='dbTzt'></legend><bdo id='dbTzt'><pre id='dbTzt'><center id='dbTzt'></center></pre></bdo></b><th id='dbTzt'></th></span></q></dt></tr></i><div id='dbTzt'><tfoot id='dbTzt'></tfoot><dl id='dbTzt'><fieldset id='dbTzt'></fieldset></dl></div>
      • <legend id='dbTzt'><style id='dbTzt'><dir id='dbTzt'><q id='dbTzt'></q></dir></style></legend>
          <bdo id='dbTzt'></bdo><ul id='dbTzt'></ul>

              <small id='dbTzt'></small><noframes id='dbTzt'>

                <tbody id='dbTzt'></tbody>

              • 本文介绍了为什么我无法在使用 Maven 的 Junit 测试运行中访问 src/test/resources?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在运行以下代码时遇到问题:

                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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:修改 void 函数的输入参数,然后读取 下一篇:如何使用 Mockito 测试 DAO 方法?

                相关文章

                1. <small id='pvols'></small><noframes id='pvols'>

                  <i id='pvols'><tr id='pvols'><dt id='pvols'><q id='pvols'><span id='pvols'><b id='pvols'><form id='pvols'><ins id='pvols'></ins><ul id='pvols'></ul><sub id='pvols'></sub></form><legend id='pvols'></legend><bdo id='pvols'><pre id='pvols'><center id='pvols'></center></pre></bdo></b><th id='pvols'></th></span></q></dt></tr></i><div id='pvols'><tfoot id='pvols'></tfoot><dl id='pvols'><fieldset id='pvols'></fieldset></dl></div>

                  • <bdo id='pvols'></bdo><ul id='pvols'></ul>

                2. <legend id='pvols'><style id='pvols'><dir id='pvols'><q id='pvols'></q></dir></style></legend>

                  1. <tfoot id='pvols'></tfoot>