简体   繁体   中英

Problem running a test with src/main and src/test

Newbie to Java having issue with an existing code base.

It seems Java files in /src/code are not being picked up.

Other devs here use IntelliJ, which runs tests fine out of the box (default config). I'm trying to use VSCode but also get the same result running via the terminal:

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.

Note that command clicking the 'missing' file opens its source in VSCode, so I know it's there.

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. 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. When I ran the tests via the "Java Test Runner" extension, they ran fine.

I told you the issue was my stupidity! Thanks for the ideas anyways!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM