approvals/ApprovalTests.Java

Approval tests are failing when unit tests are run in parellel with performance load i.e. same test is run 100s of times currently

Closed this issue · 1 comments

            java.lang.reflect.InvocationTargetException: null
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
                at java.base/java.lang.reflect.Method.invoke(Method.java:578)
                at com.github.noconnor.junitperf.statements.FullStatement.evaluate(FullStatement.java:37)
                at com.github.noconnor.junitperf.statements.EvaluationTask.evaluateStatement(EvaluationTask.java:103)
                at com.github.noconnor.junitperf.statements.EvaluationTask.run(EvaluationTask.java:60)
                at com.github.noconnor.junitperf.statements.PerformanceEvaluationStatement.lambda$createTask$0(PerformanceEvaluationStatement.java:94)
                at java.base/java.lang.Thread.run(Thread.java:1589)
            Caused by: java.lang.Error: java.nio.file.NoSuchFileException: G:DWorkosourceexperimentsjavaedu.srcmainjavacomtejasofttestsjuju5utaprtlearnscrubbersapprovedTestMultiScrubber.testRandom.received.txt
                at com.spun.util.ObjectUtils.throwAsError(ObjectUtils.java:109)
                at com.spun.util.io.FileUtils.readFile(FileUtils.java:226)
                at org.approvaltests.approvers.FileApprover.approveTextFile(FileApprover.java:65)
                at org.approvaltests.approvers.FileApprover.approve(FileApprover.java:35)
                at org.approvaltests.Approvals.verify(Approvals.java:209)
                at org.approvaltests.Approvals.verify(Approvals.java:175)
                at org.approvaltests.Approvals.verify(Approvals.java:183)
                at org.approvaltests.Approvals.verify(Approvals.java:50)
                at com.tejasoft.tests.ju.ju5.ut.aprt.learn.scrubbers.TestMultiScrubber.testRandom(TestMultiScrubber.java:20)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)

Is there any configuration to say approval test to not create file to compare instead compare in memory while accepted one can be a file as that can be read by many threads as it is the same content..

No, there is not a way to NOT create a .received file.
Here are two solutions that might be helpful for you:

1. Read the contents of the approved file and assert equality directly

If you wanted to just read the file and compare it, you can call Approvals.getNamer() to get the approved file name.

2. Write the output to a temporary file and then call verifyFIle()

This will stop Approvals from the race condition of one test deleting the received file while another test is trying to read it.

We regret to say that we have no intentions to have ApprovalTests work off of a memory-resident file as it will be a massive architectural overhaul.