Java Mockito Testing help reading errors

This test was pulled from assignment 2, Techjobs-object-oriented-edition, in LC101 Java but the intention is for you to learn how to run certain mockito error messages.


so you google it and get something like, java - Getting Missing 1 invocation to... in - Stack Overflow.

But what is the error message really saying above? The error is because you are using the wrong assert. Why is this? Well, some background first… :slight_smile:

So in LC101 Java when writing unit tests you have to name the test EXACTLY what the instructions say because there are tests that LaunchCode wrote that are actually testing the test you are writing. The LaunchCode tests need the name to be the same because they execute your test based on that name. Furthermore, their test verifies that you write your tests correctly when they run…thus giving you the “green checkmark” or that horrible “red x” in your github repo.

Now that we covered that lets see the LaunchCode test:
See comment for this I’m only able to post one photo

Compared to the student’s test:
See comment for this I’m only able to post one photo

Now that we have all the information we can talk about the above error. The error states we are missing 1 invocation of assertEquals so assertTrue in the student’s test is not testing what LaunchCode is wanting^1. Since assertTrue is wrong let’s change that to assertEquals:
assertEquals(true, jerb.toString().contains("Name: Stable Cleaner")

So we run the code again and get a new error…meaning we are still wrong :frowning: . This is still wrong because of the anyString, anyString inside of the LaunchCode test photo. In order to get this to work, we need to provide strings in both arguments to the assertEquals so changing it to:
assertEquals("\nID: 1\nName: Stable Cleaner\nEmployer: Hercules Outsourcing\nLocation: Olympia\nPosition Type: Equestrian sanitation\nCore Competency: Hydrology\n", jerb.toString());
BOOM! It works!

I hope this helps some people learn how to read or reason about tests :smiley:!

^1. It’s important to note that this test is technically not wrong for a test because it’s testing the same thing just in a different way. But it is wrong if you want to get that “green checkmark” instead of that horrible “red x” in github.

Now that we covered that lets see the LaunchCode test:

Compared to the student’s test: