简体   繁体   English

使用src / main和src / test运行测试时出现问题

[英]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.

相关问题 应用程序(src / main)运行时,类路径中的src / test / resources中的文件是? - Are files in src/test/resources on classpath while application (src/main) is running? 是否可以从 src/main 中的 src/test 加载测试类? - Is it possible to load test classes from src/test in src/main? Maven布局:如何确保src / main不依赖于src / test? - Maven layout: How to be sure that src/main does not depend on src/test? Maven项目中src / main / java和src / test / java之间的区别 - Difference between src/main/java and src/test/java in a Maven project JAVA - 无法将 src/test/java 导入 src/main/java - JAVA - can't import src/test/java to src/main/java 让 Eclipse 使用 src/test/resources 而不是 src/main/resources - Make Eclipse use src/test/resources instead of src/main/resources IntelliJ IDEA:库在src \\ test \\ java上可用,但在src \\ main \\ java上不可用 - IntelliJ IDEA: library available on src\test\java but not on src\main\java 如何从src / main / java中的src / test / resources中读取道具 - How to read props from src/test/resources in src/main/java 来自src / test的Jar文件中的主类 - Main class in Jar file from src/test 在 Eclipse 中为 spring 运行单元测试时将 src/main/resources 添加到类路径 - Add src/main/resources to classpath when running unit test in eclipse for spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM