踏雪须眉 2018-06-15 05:57 采纳率: 0%
浏览 1751
已结题

Spring Junit 运行错误

[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条回答

  • 踏雪须眉 2018-06-19 02:41
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序