Approval testing assertions cannot find the test

Hi all, I’m currently working through the “Implementing Assertions” part of the intermediate course (1-6-2) and I’m having problems with setting up the approval test in the “API Check and Approval Testing” section. The test runs fine (albeit without actually testing anything) until I add the assertion line:

Approvals.verify(response.getBody().prettyPrint());

Once I add it and try to run the test, I see the following error:

com.spun.util.FormattedException: Didn’t find com.ministryoftesting.ProjectApiTest under /<path to the repo>/mot-cert-support-app-java

	at com.spun.util.ClassUtils.getSourceDirectory(ClassUtils.java:103)
	at com.spun.util.ClassUtils.getSourceDirectory(ClassUtils.java:108)
	at com.spun.util.tests.TestUtils.getInfo(TestUtils.java:195)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:182)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:174)
	at org.approvaltests.namer.StackTraceNamer.<init>(StackTraceNamer.java:17)
	at org.approvaltests.Approvals$1.load(Approvals.java:41)
	at org.approvaltests.Approvals$1.load(Approvals.java:38)
	at org.approvaltests.Approvals.createApprovalNamer(Approvals.java:257)
	at com.spun.util.ArrayUtils.getOrElse(ArrayUtils.java:309)
	at org.approvaltests.core.Options$FileOptions.getNamer(Options.java:114)
	at org.approvaltests.Approvals.verify(Approvals.java:183)
	at org.approvaltests.Approvals.verify(Approvals.java:50)
	at org.approvaltests.Approvals.verify(Approvals.java:46)
	at com.ministryoftesting.ProjectApiTest.testGettingProject2(ProjectApiTest.java:37)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

I understand that if the test has run correctly, two files would have been created for the approved and received results - I believe that this is the part that is failing here, as no files are created.

I tried to troubleshoot this but I’m currently stuck and out of ideas - has anyone seen this error previously or can think of potential fix or workaround? Any suggestions would be appreciated - thanks in advance!

2 Likes

Hi,

I’ve had a little look into this but I’m at a loss at what is happening. Perhaps you could commit your code to a repository and share it with us. I can then take a look and see if there is anything I can suggest.

3 Likes

The package for ProjectApiTest is actually named as com.ministryoftesting and so it can’t find it because it expects it to be under /com/ministryoftesting/ProjectApiTest but it actually is under /com.ministryoftesting/ProjectApiTest.
To fix that you have to create com package, then ministryoftesting package under it and move all the test files there. Happy testing :slight_smile:

3 Likes

That fixed it! Thank you very much!