Search code examples
intellij-ideajmockit

How to configure IntelliJ IDEA inspection "JUnit test method without any assertions" to work with jmockit's Verifications?


I have this JUnit test:

@Test
public void testExecuteReverseAcknowledgement(@Mocked final MessageDAO messageDAO)  {
    //...

    classUnderTest.execute(messageContext, actionContext);

    Verifications verifications = new Verifications() {{
            messageDAO.setAcknowledgement("APC");
        }};
}

It works as needed, assertions are done in the Verifications block (http://jmockit.org/tutorial/Mocking.html#model)

Unfortunately, IntelliJ IDEA produces a warning: "Unit test method 'testExecuteReverseAcknowledgement()' contains no assertions".

It is possible to configure this inspection and specify classes with methods that Intellij will consider as assertions:

IntelliJ inspections settings window

But I don't seem to be able to specify the mockit.Verifications() Constructor there. I've tried "mockit.Verifications" as class name and ".*", "new", "()" as method names.

My question is, how can I specify Verifications class as assertion so that IntelliJ does not produce that warning?


Solution

  • I guess, unfortunately, IDEA searches any method other than the constructor.

    I've checked sources and made a debug IDEA. Pattern ".*" is correct, but this code does not execute for a constructor.

    enter image description here

    You can see the code here: https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionBase.java

    It's a good opportunity to make a feature request :)