1、junit 不需要开启页面进行测试,启动junit需要加载以下2个引用@RunWith(SpringRunner.class),@SpringBootTest。@Test 每个测试类都需要加上一个,选中启动即可。
test测试包必须在启动类的子包里面。
package com.web.test;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.web.shop.bo.Shop;
import com.web.shop.dao.ShopDao;
import com.web.shop.service.ShopService;
import com.web.user.bo.User;
import com.web.user.service.UserService;
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyTest {
@Autowired
UserService userService;
@Autowired
ShopService shopService;
@Autowired
ShopDao dao;
@Test
public void testLogin(){
User u = userService.login("123", "1231");
System.out.println(u);
}
@Test
public void shopQuery(){
List<Shop> ss = dao.queryShops();
for(Shop s : ss){
System.out.println(s.getName());
}
}
}
2、外部跳转使用redirect:/
原文:http://www.cnblogs.com/hufeng1989/p/7710817.html