正确方法:
/** * *@author:sawsh * *@date:2021/3/8 * *@Description: **/ import com.sawsh.StartApplication; import com.sawsh.entity.User; import com.sawsh.mapper.UserDao; import com.sawsh.service.UserService; 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.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; import java.util.List; /** * *@author:sawsh * *@date:2021/3/5 * *@Description: **/ //@SpringBootTest @RunWith(SpringRunner.class) @SpringBootTest(classes = StartApplication.class) public class UserTest { @Autowired private UserDao userDao; @Autowired private UserService userService; @Test public void toTest(){ List<User> userLogins = userDao.queryAll(); userLogins.forEach(e-> System.out.println(e)); } }
StartApplication是启动类