找不到测试类-Spring Boot

时间:2018-12-26 11:49:04

标签: spring-boot junit java-7

我们有一个spring boot应用程序,并为服务类编写了测试用例。当我以右键单击->运行方式-> JUnit测试运行测试用例时,该测试用例正在运行。但是当我通过Maven运行它时,找不到它。我的测试课如下:

package dk.tdc.fasapi.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import dk.tdc.fasapi.repository.implementation.jdbc.IncidentDetailsRepo;
import dk.tdc.fasapi.requestResponse.incidents.getdetails.IncidentDetails;

@RunWith(MockitoJUnitRunner.class)
public class TestIncidentDetailsService {

    private Map<String, Object> fasoDetailsMap = null;
    private List<Map<String, Object>> subStateMapList = null;

    @Mock
    private IncidentDetailsRepo incidentDetailsRepo;

    @InjectMocks
    private IncidentDetailsService incidentDetailsService;

    @Before
    public void beforeMethod() {
        fasoDetailsMap = new HashMap<>();
        fasoDetailsMap.put("FaultDescription", "Test Description");
        fasoDetailsMap.put("UrgentCode", "01");
        fasoDetailsMap.put("LID", "12345678");
        fasoDetailsMap.put("CustomerName", "TDC");
        fasoDetailsMap.put("CustomerPhone", "11223344");
        fasoDetailsMap.put("ExtRefId", "1234");
        fasoDetailsMap.put("SSID", "0001");

        Map<String, Object> subStateMap = new HashMap<String, Object>();
        subStateMap.put("X_CURRENT_STATUS", "Accepted");
        subStateMapList = new ArrayList<Map<String,Object>>();
        subStateMapList.add(subStateMap);
    }

    @Test
    public void testExecuteOpenFaso() throws Exception {
        Mockito.when(incidentDetailsRepo.getOpenFasoDetails(Mockito.anyString())).thenReturn(fasoDetailsMap);
        Mockito.when(incidentDetailsRepo.getCurrentStatus(Mockito.anyString())).thenReturn(subStateMapList);
        IncidentDetails incidentDetails = incidentDetailsService.execute("20181225-000001");
        Assert.assertEquals(incidentDetails.getId(), "20181225-000001");
        Assert.assertEquals(incidentDetails.getStatus(), "Open");
        Assert.assertEquals(incidentDetails.getTitle(), "Test Description");
        Assert.assertEquals(incidentDetails.getSeverity(), "01");
        Assert.assertEquals(incidentDetails.getParameter().getType(), "LID");
        Assert.assertEquals(incidentDetails.getParameter().getValue(), "12345678");
        Assert.assertEquals(incidentDetails.getContact().getName(), "TDC");
        Assert.assertEquals(incidentDetails.getContact().getNumber(), "11223344");
        Assert.assertEquals(incidentDetails.getReferences().getTicket(), "1234");
        Assert.assertEquals(incidentDetails.getReferences().getSsid(), "0001");
        Assert.assertEquals(incidentDetails.getReferences().getContractor(), "ENIIG180619");
        Assert.assertEquals(incidentDetails.getSubState(), "Accepted");
    }

    @Test
    public void testExecuteClosedFaso() throws Exception {
        Mockito.when(incidentDetailsRepo.getOpenFasoDetails(Mockito.anyString())).thenReturn(null);
        Mockito.when(incidentDetailsRepo.getClosedFasoDetails(Mockito.anyString())).thenReturn(fasoDetailsMap);
        Mockito.when(incidentDetailsRepo.getCurrentStatus(Mockito.anyString())).thenReturn(subStateMapList);
        IncidentDetails incidentDetails = incidentDetailsService.execute("20181225-000001");
        Assert.assertEquals(incidentDetails.getId(), "20181225-000001");
        Assert.assertEquals(incidentDetails.getStatus(), "Closed");
        Assert.assertEquals(incidentDetails.getTitle(), "Test Description");
        Assert.assertEquals(incidentDetails.getSeverity(), "01");
        Assert.assertEquals(incidentDetails.getParameter().getType(), "LID");
        Assert.assertEquals(incidentDetails.getParameter().getValue(), "12345678");
        Assert.assertEquals(incidentDetails.getContact().getName(), "TDC");
        Assert.assertEquals(incidentDetails.getContact().getNumber(), "11223344");
        Assert.assertEquals(incidentDetails.getReferences().getTicket(), "1234");
        Assert.assertEquals(incidentDetails.getReferences().getSsid(), "0001");
        Assert.assertEquals(incidentDetails.getReferences().getContractor(), "ENIIG180619");
        Assert.assertEquals(incidentDetails.getSubState(), "Accepted");
    }

    @After
    public void afterMethod() {
        fasoDetailsMap = null;
    }

}

有人可以建议我是否必须在测试类上添加其他注释以使其可见吗?

0 个答案:

没有答案