com.sun.jdi.ClassNotLoadException:调用方法时未加载类型

时间:2018-01-04 11:14:05

标签: java spring-mvc junit mockito

需要帮助编写Junit。 我收到错误" com.sun.jdi.ClassNotLoadException:调用方法时没有加载类型。"从我的Junit测试类中击中控制器方法。 modelView = avamar.getCompGuidePage(productVersion,avamarComponent,model); 上面的行显示了classNotLoadException dut。 Debug不允许我输入控制器方法断点。

这是测试和实际课程。

测试课

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;

import com.emc.brsit.avamar.vo.AvamarAllComponentsVO;
import com.emc.brsit.common.util.CustomCompGuideException;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:/Project/applicationContext servlet.xml")
public class AvamarControllerTest {

    private final static Logger LOGGER = LoggerFactory
                    .getLogger(AvamarControllerTest.class);
    @Mock
    private AvamarController avamar;
    @Mock
    private AvamarAllComponentsVO avamarComponent;

    /*@Before
    public void setupMock() {
        avamar = mock(AvamarController.class);
        avamarComponent = mock(AvamarAllComponentsVO.class);
    }*/

    @Before
    public void setupMock() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testGetCompGuidePage()  {
        String productVersion ="7.5";
        Model model = null;
        ModelAndView modelView = new ModelAndView();
        try {
            modelView = avamar.getCompGuidePage(productVersion , avamarComponent, model );
        } catch (CustomCompGuideException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String abc = "new";
    }
}

实际控制器类方法

@RequestMapping(value = "/getAvamarCompGuidePage", method = RequestMethod.GET)
public ModelAndView getCompGuidePage(
@ModelAttribute("productVersion") String productVersion,
    @ModelAttribute("allComponentsVO") AvamarAllComponentsVO allComponentsVO,
            Model model) throws CustomCompGuideException{

        LOGGER.debug("AvamarController::getCompGuidePage()::Start::");
        //System.out.println("--------------Controller--------------");
        try {
        model.addAttribute("featureInstant",
                avamarOSBO.getApp_Hype_Feat_Filters("Features"));
    model.addAttribute("clientOSGrouped",avamarOSBO.getClientOSGroupedBY());
        model.addAttribute("clientOSGroupedos_vendor",
                avamarOSBO.getClientOSGroupedByVendor());
        model.addAttribute("clientOS", avamarOSBO.getClientOS());

        model.addAttribute("ndmpOSGrouped",avamarOSBO.getNDMPOSGroupedBY());

    // model.addAttribute("features",
        // avamarOSBO.getApp_Hype_Feat_Filters("Extended Retention"));

        // model.addAttribute("featOS", avamarOSBO.getFeatType2OS());
model.addAttribute("hypeOSGroupedType2",avamarOSBO.getHypeOSGroupedBYType2());


        model.addAttribute("featOSGroupedos_vendor",
                avamarOSBO.getFeatType2OSGroupedByVendor());
            // Important for Navigation
        model.addAttribute("link",productVersion);
        }catch(Exception ex) {
            LOGGER.debug("SITE DOWN DUE TO ERROR::-->" + ex.getMessage());
            throw new CustomCompGuideException(ex.getMessage());
        }
        LOGGER.debug("AvamarController::getCompGuidePage()::END::");
            return new ModelAndView("AvamarCompGuideApp");
    }

1 个答案:

答案 0 :(得分:0)

您正在模拟AvamarController上执行方法。

尝试以下代码。在已经进行更改的大写字母中添加了评论

readarray -t < <(ls -l)
for object in "${MAPFILE[@]}"; do echo "$object"; done