1. springmvc单元测试配置
junit
junit
${junit.version}
test
package com.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@Slf4j
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext_.xml"})
public class ImageTask {
@Autowired
ItemService itemService;
@Test
public void request() {}
}
2. springboot单元测试配置
org.springframework.boot
spring-boot-starter-test
package com.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SmsTest {
@Autowired
private AmqpTemplate amqpTemplate;
@Test
public void testSend() throws Exception{}
}