1. 幾個基本的參數
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WendaApplication.class)
第一個參數說明用junit4
第二個參數說明spring的上下文,後面纔可以使用@Autowired
@BeforeClass 在一個測試class所有測試方法前面調用,可以用來執行一些方法公用的初始化
@AfterClass
在一個測試class所有測試方法後面調用,一些方法公用的初始化的回收
@Test
測試方法的註解
@Before
在測試方法之前調用,每一個方法單獨調用
@After
在測試方法之後調用,每一個方法單獨調用
2. 測試也有三種測試
1.對於期望值與實際值的對比(最常用)
Assert.assertEquals(-1, likeService.getLikeStatus(123, 1, 1));
2.對於非法參數是否拋出異常
@Test(expected = IllegalArgumentException.class)
public void testException() {
System.out.println("testException");
throw new IllegalArgumentException("異常發生了"); }
3.壓力測試
通過ab就能夠大概知道自己機器能跑多少數據