Bug 64597 - junitlauncher does not identify and execute unit test which uses mocking framework Mockito
Summary: junitlauncher does not identify and execute unit test which uses mocking fram...
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.10.5
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-13 06:05 UTC by mgandhi
Modified: 2020-08-10 06:27 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mgandhi 2020-07-13 06:05:46 UTC
Hi,
The junitlauncher does not identify and execute unit test which uses mocking framework Mockito. The other unit test cases which are not using the mocking framework are identified and executed successfully. Also, the IntelliJ Idea IDE successfully executes the unit test which uses mocking framework Mockito.

Execution Log:
 [junitlauncher] Test run finished after 0 ms
 [junitlauncher] [         1 containers found      ]
 [junitlauncher] [         0 containers skipped    ]
 [junitlauncher] [         1 containers started    ]
 [junitlauncher] [         0 containers aborted    ]
 [junitlauncher] [         1 containers successful ]
 [junitlauncher] [         0 containers failed     ]
 [junitlauncher] [         0 tests found           ]
 [junitlauncher] [         0 tests skipped         ]
 [junitlauncher] [         0 tests started         ]
 [junitlauncher] [         0 tests aborted         ]
 [junitlauncher] [         0 tests successful      ]
 [junitlauncher] [         0 tests failed          ]

Environment:
OS: Winodws 10 and Centos 7
IDE: IntelliJ Idea 2019.1.3, 2020.1
ANT: 1.10.5
Mockito: 3.3.3
JDK: OpenJDK 1.8 

Code:
@ExtendWith(MockitoExtension.class)
class FileHandlerTest {

    @Mock
    ServletContext application;

    @Test
    void getLegacyStaticFilePath() {
        FileHandler underTest = new FileHandler();
        when(application.getAttribute("envglobal")).thenReturn("windev");

        Map<String, String> filePathMap=underTest.getLegacyStaticFilePath("csv",application);

        assertAll("static file path",
                () -> assertEquals("C:\\gta\\supportive_documents\\", filePathMap.get("supportDoc")),
                () -> assertEquals("C:\\gta\\gtc_load\\", filePathMap.get("loadDoc")),
                () -> assertEquals("C:\\gta\\ttg_reports\\", filePathMap.get("ttgReportsDoc")));
    }
}

Other Observation:
Test report TEST-com.XXX.FileHandlerTest.txt created with 0 byte.
Comment 1 Jaikiran Pai 2020-07-19 05:17:07 UTC
Would you be able to attach a simple build.xml file which will help us reproduce this issue easily?
Comment 2 mgandhi 2020-07-21 13:59:08 UTC
Here is the build step which invokes the JUnit 
<!-- Run Unit Tests and Generate Report -->
  <target name="test.junit.launcher" depends="compile.module.goda1.production">
    <echo message="Launcher Started" />
    <mkdir dir="${test.report.dir}" />
    <junitlauncher haltOnFailure="true" printSummary="true" >
      <classpath>
        <!-- the test classes themselves -->
        <pathelement location="${goda1.testoutput.dir}"/>
        <pathelement location="${goda1.output.dir}"/>
      </classpath>
      <testclasses outputdir="${test.report.dir}">
        <fileset dir="${goda1.testoutput.dir}">
          <include name="**/*Test.class"/>
        </fileset>
        <listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
        <listener type="legacy-plain" sendSysOut="true" />
      </testclasses>
    </junitlauncher>
  </target>

The ${goda1.testoutput.dir} represents compiled output of the test classes and the ${goda1.output.dir} represents the compiled output of the project source code.
Comment 3 Jaikiran Pai 2020-07-21 14:30:16 UTC
Thank you for that build snippet. I just gave this a quick try locally and was able to see that the test runs fine.

I noticed in your output that you are using Ant 1.10.5 release. Could you try this against the latest released 1.10.8 (the version I tried against) and see if it works there?
Comment 4 mgandhi 2020-07-23 05:37:00 UTC
Yes, I am using ANT 1.10.5 and also mentioned that at the time of raising defect. 

Going through your response, does that mean ANT 1.10.5 doesn't recognize unit test written using mocking framework MOckito 3.3? Is it a Bug?

Also, I gave a try using ANT 1.10.8 having the same structure and got below error:
failed to launch in-vm tests.
Comment 5 mgandhi 2020-08-10 06:27:53 UTC
Can anyone please look into this? Appreciate earliest resolution.

Thanks.