How to run junit tests in vscode?

working with one of the students to do some junit testing. Fortunately, it’s testing for some computational code, so don’t need to do a lot of work with Mockito, etc (this is a good article on setting up for that kind of testing:

I was able to get junit tests to run at build time by looking at ,

Is there a way to run a single test without rerunning a build (which runs all tests?). In eclipse, I can just right click on a test and run it…

1 Like

See Unit Testing: wpiHaljni

as I read it, running the “test” gradle command should do it. it does complete “successfully”, but I don’t see any output from the tests (there are some printlns in there…)

The gradle test task and also the build tasks runs all of your tests, but doesn’t actually show the output of each test by default.

If you want to show standard streams when running tests on the command line, this can help you: Running your tests on the command line with Gradle | by Chuck Greb | Android Testing | Medium

Basically you would put

test {
    showStandardStreams true

In your build.gradle. I haven’t tested that with the standard WPI project set up, but I assume that it will work.

Also, before you claim this doesn’t work, make sure you do a ./gradlew clean test or gradlew.bat clean test. (Sometimes you need to run a clean before things start to just work)


results in

* What went wrong:
A problem occurred evaluating root project 'FRC3620_2020_DougReallyBasic'.
> Could not find method showStandardStreams() for arguments [true] on task ':test' of type org.gradle.api.tasks.testing.Test.


tasks.withType(Test) { 
  testLogging {
    exceptionFormat "full"
    events "started", "skipped", "passed", "failed"
    showStandardStreams true


1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.