R026 Failed to create Spring context

Hello !

I am getting R026 Failed to create Spring context error., could you please share the root cause for below error and what fix we need to apply ?

// Diffblue Cover was unable to write a Spring test,
// so wrote a non-Spring test instead.
// Reason: R026 Failed to create Spring context.
// Attempt to initialize test context failed with
// java.lang.IllegalStateException: Failed to load ApplicationContext
// at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
// at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
// at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
// at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
// at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
// at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
// at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
// at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
// at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
// org.mockito.exceptions.base.MockitoException:
// Cannot mock/spy class java.lang.Integer
// Mockito cannot mock/spy because :
// - Cannot mock wrapper types, String.class or Class.class
// at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
// at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
// at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
// at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
// at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
// at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
// at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
// at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
// at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
// See Working with code R026 | Diffblue Docs to resolve this issue.

Hi @PRRanjan

Thank you for using Cover and contacting us!
There can be many reasons why you see R026, it’s hard to see the root solely from this stack trace. For example, often the solution here will be to declare your Spring profiles to Cover - more information here, however, there is more than one solution. The best action is to view our documentation on this R026 output code (found here), alongside the output in the log file (guide to find the log file here).

If you would like, I would be happy to help pick out some solutions if you upload the log file here.

Kind regards,
Jane @ Diffblue