I’ve managed to create some unit tests using Mockito on my team’s 2021 project for the drive subsystem. I’ve gotten the test to successfully run, however, VSCode doesn’t provide any autocompletion or javadoc tooltips in the test file. It also doesn’t recognise the tests and bring up the “run test” and “debug test” buttons on the file. And it reports the following: DriveSubsystemTest.java is not on the classpath of project TB2021, only syntax errors are reported
DriveSubsystemTest.java is located in TB2021/src/test/java/frc/robot/subsystems/DriveSubsystemTest.java.
I’ve tried adding another source set in the build.gradle file with the following addition:
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
test {
java {
srcDir 'src/test/java'
}
}
}
I haven’t tried using IntelliJ, and I’m not really considering it at the moment for this. VSCode has had pretty good code completion for me in the rest of the robot code, and outside of the WPILib extensions, is problem free. Only WPILib crap is buggy as hell…
For Java, all the intellisence including for testing is handled by the redhat Java extension and the Java test extension.
Usually when the test classpath can’t be counted is because testing wasn’t enabled at the start, and the Java extension doesn’t refresh correctly. You can have it completely refresh by running the ‘Clean Java Workspace’ command from the command pallet. After resetting at least intellisense should work.
Interestingly, if I disable the ‘Test Runner for Java’ extension and reload the ‘Language Support for Java’ extension, Intellisense starts working again. But with the ‘Test Runner’ extension enabled, Intellisense doesn’t work. Not sure if anyone else has seen this issue.
Thats bizarre for sure. It doesn’t 100% surprise me, as those extensions are written by separate companies and its possible something broke in one of the 2 extensions.
I can dig through the issues later to check. You should be able to reproduce this 100% with just a normal Java project, as at least for Java we don’t interface with the intellisense engine at all.
You also might be able to run on logging for both extensions (They both have a way to do it I think) and that might give some insight.
Figured out a solution for now. I’ve downgraded the Red Hat Java extension to version 0.81.0. That fixes the issue. I can now test and enjoy IntelliSense at the same time. Red Hat must have broken something in the later versions.
Must have just been some weirdness on my end. I upgraded back to the latest version of the Red Hat Java extension and its working fine. IntelliSense and testing both work.