I have configured surefire report plugin to my Spring+Maven based project to generate test report(s) and the surefire report plugin able to identify my test class but not running the test cases present in it.
Dependency used in pom.xml
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</reporting>
While building the project it genertes the result as bellow
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.thales.idct.controller.LopaReConfigControllerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@1829ae5e
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.225 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
Even the same things is present in *.html report as well.
Bellow is my test case code
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigWebContextLoader.class)
@WebAppConfiguration
public class LopaReConfigControllerTest {
public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
// Application dependency
private MockMvc mvc;
private LopaReConfigRepositoryImpl lopaImpl;
/*@Spy
@InjectMocks
LopaReConfigService lopaReConfigService = new LopaReConfigService();*/
@Mock
LopaReConfigService lopaReConfigService;
@Mock
CommonUtil commonUtil;
@Mock
ProcessLopaReconfigFile processLopaReconfigFile;
@Mock
DBImportRepository dbImportRepository;
@InjectMocks
MockHttpSession session;
@Autowired
WebApplicationContext context;
@InjectMocks
LopaReConfigController lopaReConfigController;
@Mock
UserSessionPool sessionPool;
// Building and Injecting mocked dependency(s) to controller
@Before
public void setup() {
// Process mock annotations
MockitoAnnotations.initMocks(this);
this.mvc = MockMvcBuilders.standaloneSetup(lopaReConfigController).build();
lopaImpl = new LopaReConfigRepositoryImpl();
}
@Test
public void test_getSeatLayoutDisplay() throws Exception {
// Construct JSON data to pass as parameter
BASeatkitDataFeeder seatKitDataFeeder = new BASeatkitDataFeeder();
Gson gson = new Gson();
CommonUtil util = new CommonUtil();
StringBuffer filePathBuff = new StringBuffer();
String jsonStub = "";
String columnXMl = "";
filePathBuff.append(util.getLopaReConfigPath("RAJESH-300ER", "RAJESH-300ER-B777-v300B"));
filePathBuff.append(LoadPropertyFiles.getInstance().getProperty("INPUT"));
//seatKitDataFeeder.setFilepath(XmlFilePath);
seatKitDataFeeder.setMode("");
seatKitDataFeeder.setFilename("");
seatKitDataFeeder.setBuildVersion("Base");
seatKitDataFeeder.setCarrierName("RAJESH-300ER");
seatKitDataFeeder.setDbId("1558");
seatKitDataFeeder.setDbName("RAJESH-300ER-B777-v300B");
seatKitDataFeeder.setSessionId(session.getId());
seatKitDataFeeder.setFilepath(filePathBuff.toString());
String seatKitXmlFilePath = filePathBuff.append(LoadPropertyFiles.getInstance().getProperty("XMLS")).toString();
columnXMl = filePathBuff.append(Constants.COLUMN_XML_FILENAME).toString();
BASeatKitInfo BAinfo = lopaImpl.getBASeatKit(seatKitXmlFilePath);
KitLayout kitLayout = lopaImpl.getBAColumnSeatKit(seatKitXmlFilePath+Constants.SEATKIT_COLUMN_XML_FILENAME,columnXMl);
// Mock the service results and feed
when(commonUtil.getLopaReConfigPath("RAJESH-300ER", "RAJESH-300ER-B777-v300B")).thenReturn(filePathBuff.toString());
when(lopaReConfigService.getBASeatKit(Mockito.anyString())).thenReturn(BAinfo);
when(lopaReConfigService.getBAColumnSeatKit(Mockito.anyString(),Mockito.anyString())).thenReturn(kitLayout);
// Construct JSON Object
jsonStub = gson.toJson(seatKitDataFeeder);
// Test method logic
mvc.perform(post("/getSeatLayoutDisplay")
.contentType(MediaType.APPLICATION_JSON).content(jsonStub))
.andExpect(status().isOk()) // After hitting specific URL/URI check the status code fall under 200 series
.andExpect(content().contentType(APPLICATION_JSON_UTF8)); // Check the return statement is JSON
//.andExpect(jsonPath("$.fieldErrors", hasSize(1)));
// Verify that the getBASeatKit() method of the lopaReConfigService is called only once during execution.
verify(lopaReConfigService, times(0)).getBASeatKit(seatKitXmlFilePath);
verify(lopaReConfigService, times(0)).getBAColumnSeatKit(seatKitDataFeeder.getFilepath(),columnXMl);
}
@Test
public void testGetBAColumnSeatKit() throws Exception{
BAColumnSeatkitDataFeeder seatKitDataFeeder = new BAColumnSeatkitDataFeeder();
Gson gson = new Gson();
CommonUtil util = new CommonUtil();
StringBuffer filePathBuff = new StringBuffer();
String jsonStub = "";
String columnXMl = "";
String centerXmlFilePath = "";
LopaReConfigController cntrl = PowerMockito.spy(lopaReConfigController);
seatKitDataFeeder.setMode("");
seatKitDataFeeder.setFileName("");
seatKitDataFeeder.setBuildVersion("Base");
seatKitDataFeeder.setCarrierName("BRITISH");
seatKitDataFeeder.setDbId("1514");
seatKitDataFeeder.setDbName("BRITISH-B787-PI-2-8");
seatKitDataFeeder.setSessionId(session.getId());
seatKitDataFeeder.setFilePath(filePathBuff.toString());
when(processLopaReconfigFile.getImportStatus(Integer.parseInt(seatKitDataFeeder.getDbId()))).thenReturn(Constants.SUCCESS);
filePathBuff = new StringBuffer(util.getLopaReConfigPath(seatKitDataFeeder.getCarrierName(),seatKitDataFeeder.getDbName()));
filePathBuff.append(LoadPropertyFiles.getInstance().getProperty("INPUT"));
String seatKitXmlFilePath = filePathBuff.append(LoadPropertyFiles.getInstance().getProperty("XMLS")).toString();
StringBuffer columnXmlFileBuf = new StringBuffer(filePathBuff);
columnXmlFileBuf.append(Constants.COLUMN_XML_FILENAME);
String leftXmlFilePath = filePathBuff.append(Constants.COLUMN_SEATKIT).toString();
String columnXmlFilePath = columnXmlFileBuf.toString();
if("Base".equalsIgnoreCase(seatKitDataFeeder.getBuildVersion())){
centerXmlFilePath = leftXmlFilePath;
} else {
centerXmlFilePath=lopaImpl.getLopaFilePath(seatKitDataFeeder.getBuildVersion(),seatKitDataFeeder.getDbId());
}
BASeatKitInfo seatKitInfo = lopaImpl.getBASeatKit(seatKitXmlFilePath);
KitLayout columnSeatKitLeft = lopaImpl.getBAColumnSeatKit(leftXmlFilePath,columnXmlFilePath);
KitLayout columnSeatKitCenter = lopaImpl.getBAColumnSeatKit(centerXmlFilePath,columnXmlFilePath);
Map<String,String> powerMap = lopaImpl.getPowerUnitInfo(seatKitXmlFilePath);
List<LayoutDesignVersionEntity> listLDVE = dbImportRepository.getLayoutDesignVersionList(Integer.parseInt(seatKitDataFeeder.getDbId()));
User user = new User();
user.setAirlineName("BRITISH-B787-PI-2-8");
user.setGroupName("FFF");
user.setLastLoginTime("12:12:12 10:09:09.656");
user.setPassword("FFF");
user.setUserName("FFF");
UserSessionPool.getInstance().addUser(user);
// when(commonUtil.getLopaReConfigPath(Mockito.anyString(),Mockito.anyString())).thenReturn(filePathBuff.toString());
//when(commonUtil.getLopaReConfigPath("RAJESH-300ER", "RAJESH-300ER-B777-v300B")).thenReturn(filePathBuff.toString());
when(commonUtil.getLopaReConfigPath("RAJESH-300ER", "RAJESH-300ER-B777-v300B")).thenReturn(filePathBuff.toString());
when(lopaReConfigService.getBASeatKit(seatKitXmlFilePath)).thenReturn(seatKitInfo);
when(lopaReConfigService.getBAColumnSeatKit(leftXmlFilePath,columnXmlFilePath)).thenReturn(columnSeatKitLeft);
when(lopaReConfigService.getBAColumnSeatKit(centerXmlFilePath,columnXmlFilePath)).thenReturn(columnSeatKitCenter);
when(lopaReConfigService.getPowerUnitInfo(seatKitXmlFilePath)).thenReturn(powerMap);
when(dbImportRepository.getLayoutDesignVersionList(Integer.parseInt(seatKitDataFeeder.getDbId()))).thenReturn(listLDVE);
jsonStub = gson.toJson(seatKitDataFeeder);
System.out.println(jsonStub);
PowerMockito.doNothing().when(cntrl,"isValidUser",seatKitDataFeeder.getSessionId());
mvc.perform(post("/getSeatKitAndLopaInfo")
.contentType(MediaType.APPLICATION_JSON).content(jsonStub))
.andExpect(status().isOk());//.andExpect(jsonPath("airline", "B787-8").exists());// After hitting specific URL/URI check the status code fall under 200 series
//.andExpect(content().contentType(APPLICATION_JSON_UTF8));// Check the return statement is JSON
verify(lopaReConfigService, times(0)).getBASeatKit(seatKitXmlFilePath);
}
}
How can I run test cases present in my test class..? Is there any better test case reporting tool..?
My POM.xml file is as bellow
<build>
<finalName>${pom.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jopendocument/jOpenDocument -->
<dependency>
<groupId>org.jopendocument</groupId>
<artifactId>jOpenDocument</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.0-GA</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0-alpha4</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.53</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- http://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Unit testing dependency API's -->
<!--Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- this is included in junit, make sure junit it version 4.11 -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.3.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<!-- <version>${powermock.version}</version> -->
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Please delete the maven-surefire-report-plugin from reporting tag place the bellow plugin inside the build tag