Local Java tests pass even when my code is wrong

I’m doing the Wizards and Warriors exercise, working locally on Linux.

When I do ./gradlew test, it always passes the tests (so long as the code actually compiles), but I’m able to change the code to return garbage values that should fail the test – but gradle still says it’s okay.

If I paste the bad code into the online editor, the tests fail or succeed as expected.

I saw some documentation about skipping tests, but clicking around I didn’t find anything specifically about how the Java tests work.

  1. How do I get the local Java tests to run and work?

  2. How do I define my own tests? I’ve worked in the Racket track and there it’s easy to add your own tests.

Actually, looking at this further: it doesn’t seem like there are any tests for this exercise! The Java “log level” exercise has tests defined in src/test/java but there’s no such directory for the wizards and warriors one. Is that a bug or misconfiguration for the exercise?

You can find the test file under src/test/java. When you first get the files, all the tests except the first one will have @Disabled("Remove to run test"). You need to remove that to enable additional tests. You can also add tests to that file.

You replied while I was editing my post – there isn’t a test directory for me! Did I not download something correctly? Is the exercise missing it?

Wizards and Warriors is a concept exercise, not a practice exercise. Those tend to be configured a bit different. That said, I think there should be a src/test/java directory. How did you download things? Are you in the download directory?

» exercism download --track=java --exercise=wizards-and-warriors
Downloaded to
/.../exercism/java/wizards-and-warriors

» cd /.../exercism/java/wizards-and-warriors

» ls -1 src/test/java/
FighterTest.java
ReflectionProxy.java
WarriorProxy.java
WizardProxy.java

Huh, that’s weird – I ran that command and it does indeed get the tests directory. I have no idea how my original download didn’t have that.