2018年2月6日 | Leave a comment 问题: spring boot + junit demo 解决: package demo.boot2.service; import java.util.Objects; import javax.inject.Inject; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class StoreServiceTest { @Inject StoreService s; public StoreServiceTest() { } @Test public void testSomeMethod() { //..... } } 12345678910111213141516171819202122232425 package demo.boot2.service; import java.util.Objects;import javax.inject.Inject;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)@SpringBootTestpublic class StoreServiceTest { @Inject StoreService s; public StoreServiceTest() { } @Test public void testSomeMethod() {//..... } } 参考: