Spring Junit 运行错误 5C

[INFO ] Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
[INFO ] Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
[INFO ] Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
[INFO ] Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@234bef66, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@737996a0, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@61dc03ce, org.springframework.test.context.support.DirtiesContextTestExecutionListener@50f8360d]

代码如下:

package com.saikul.tracker.test;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import sun.rmi.runtime.Log;

@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml","classpath*:springmvc-servlet.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class TestSaikulTracker {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;


    @Before
    public void setup(){
        mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
    }


    @Test
    public void whenfetchData() throws Exception{
        String content = "[{'l':false}]";
        mockMvc.perform(MockMvcRequestBuilders.post("/api/updateParam").contentType(MediaType.APPLICATION_JSON_UTF8).content(content))
                    .andExpect(MockMvcResultMatchers.status().isOk());
    }

    @Test
    public void testJunitRunGood(){
        System.out.println("hello world ");
    }

}

基本上就是一个没有前端页面的,只提供服务的SSH项目,我加了两个jar 一个Junit的一个Spring test的,想要模拟mvc的访问restful服务
图片说明

3个回答

截图看看,你是什么系统?什么样的业务

你检查检查是不是缺少依赖jar包
[INFO ] Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!