[英]Problem running a test with src/main and src/test
Newbie to Java having issue with an existing code base. Java的新手遇到了现有代码库的问题。
It seems Java files in /src/code are not being picked up. 似乎/ src / code中的Java文件没有被拾取。
Other devs here use IntelliJ, which runs tests fine out of the box (default config). 这里的其他开发人员使用IntelliJ,它可以开箱即用地运行测试(默认配置)。 I'm trying to use VSCode but also get the same result running via the terminal: 我正在尝试使用VSCode,但也通过终端运行得到了相同的结果:
Running a test gives me a "cannot find symbol" error trying to import local classes from /src/test/... If I copy the problematic file into /src/main/... that file imports fine but error reappears with the next imported file, and so on. 尝试运行测试时,尝试从/ src / test /导入本地类给我一个“找不到符号”错误。如果我将有问题的文件复制到/ src / main /中,则该文件可以正常导入,但错误会再次出现下一个导入的文件,依此类推。
Note that command clicking the 'missing' file opens its source in VSCode, so I know it's there. 请注意,单击“丢失”文件的命令将在VSCode中打开其源代码,因此我知道它已存在。
import is standard: 导入是标准的:
import com.foo.bar.baz.math.TestMathModelFactory;
File exists under: 文件存在于:
work/src/test/java/com/foo/bar/baz/math/TestMathModelFactory.java
It builds if I put it under: 如果将其放在以下位置,它将建立:
work/src/main/java/com/foo/bar/baz/math/TestMathModelFactory.java
Expect it to import, but get: 期望它导入,但是得到:
RTPTest.java:3: error: cannot find symbol
import com.foo.bar.baz.math.TestMathModelFactory;
^
I know I'm doing something stupid, but ¯\\_(ツ)_/¯ 我知道我在做一些愚蠢的事情,但是\\ _(ツ)_ /¯
LOL, was my own Pebkac issue. 大声笑,是我自己的Pebkac问题。 I was trying to run the tests via the VScode "Code Runner" extension – which, in retrospect, has no idea how the project is set up. 我试图通过VScode“ Code Runner”扩展名运行测试-回想起来,该扩展名不知道项目的设置方式。 When I ran the tests via the "Java Test Runner" extension, they ran fine. 当我通过“ Java Test Runner”扩展名运行测试时,它们运行良好。
I told you the issue was my stupidity! 我告诉过你问题是我的愚蠢! Thanks for the ideas anyways! 无论如何,谢谢你的想法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.