Junit tests succeed during build, but not individually

With the cancellation of the season, I have been working on a software curriculum for our team, with an emphasis on introducing some best practices that we find difficult to introduce later.

To that end, I have been trying to get get Junit working with a very simple robot code base. I want to start with the minimum that works, with the intention of building on it in later lessons. I am hampered by knowing virtually no Junit.

I started with @itsmechuckb and his videos, and with the PR request he has outstanding with WPILIB. (https://www.youtube.com/channel/UCekeDJzimFuocARIjuiDrGQ ) But I don’t want to modify any existing WPILIB classes. (https://github.com/wpilibsuite/allwpilib/pull/1461/commits/5ae640ebd048e13dc0ac8e438cc936dda7abd7cf ) I also was using the RoboTote example at https://github.com/robototes/2020_Template.

I started with a simple robot and started adding stuff from the template until I ran into a problem. I then tried just cloning their template a running that. When I run the template, I get an error about missing robot_library, which apparently is a submodule in GIT. I probably an figure this out, but it does suggest that the template is somewhat more complex than I would have hoped.

However, when I tried adding stuff as needed from the template to my small robot base, I found that I got a test to run. When I did a build it ran the tests I set up and they succeeded. I forced one to fail and rebuilt and now the test failed, so the tests were definitely getting run.

The problem though is when I went to the test file and pushed the “Run Test” button, the test just exits, no results. I stepped through the test and found that it was failing in the call to HAL.initialize(500, 0);. Apparently that jumps into some JNI code that blows up. Why does it work in the build but not individually? Any ideas?

If you want to see what I have at the moment, my repo is at:

P.S. it would really be great if WPI could add testing as a first class feature.

1 Like

The Run Test button in VS Code does not work correctly. The functionality to make this work doesn’t exist because of the way native dependencies are required to be set up. I will keep looking at ways to make this work, but for now that functionality will not work.

For running tests during the build, that works correctly because in Gradle we can set up the tests to make this work correctly.

Well, that’s good to know. I have a lot less infra-structure than I thought I would need. Any hope in getting Junit support in WPILIB next year?

JUnit itself works just fine with WPILib. It’s even included in the default template. Anything more specific you’re thinking about?

1 Like

The necessity of all of the stuff to deal with the HAL. Of if that is counter-productive, a pre-configured example environment. @itsmechuckb’s PR had some stuff outside his example to make it easier to run the tests. And of course, whatever it preventing the tests from running individually. I found that running the tests all at once with the build wouldn’t stop at breakpoints. Is there a way to run the tests alone all at once and a way to do a build without running the tests?

I’m pretty sure that the breakpoints are integrated into VS Code or IntelliJ (I believe both have this problem). I’m pretty sure that it’s not possible to run the tests with breakpoints doing a standard build and I also don’t think it’s possible to do breakpoints through the command line.

See this answer: https://stackoverflow.com/questions/22505533/how-to-run-only-one-local-test-class-on-gradle#31468902

And without running the tests: https://stackoverflow.com/questions/4597850/gradle-build-without-tests