???JUnit??????Java?????е???
???????????? ???????[ 2014/7/10 11:11:57 ] ????????JUnit ??????????
????JUnit annotation???
????JUnit?????????expected??annotation?????????
@Test(expected = IllegalArgumentException.class)
public void shouldGetExceptionWhenAgeLessThan0() {
Person person = new Person();
person.setAge(-1);
}
|
?????????????????????????????????????е??????
????ExpectedException rule
????JUnit7??????????????ExpectedException??Rule??????????????
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void shouldGetExceptionWhenAgeLessThan0() {
Person person = new Person();
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("age is invalid"));
person.setAge(-1);
}
|
???????????????????????????????????е??????
???????catch-exception??
?????и?catch-exception???????????????????
??????????????
????pom.xml
????<dependency>
????<groupId>com.googlecode.catch-exception</groupId>
????<artifactId>catch-exception</artifactId>
????<version>1.2.0</version>
????<scope>test</scope> <!-- test scope to use it only in tests -->
????</dependency>
?????????????д?????
????@Test
????public void shouldGetExceptionWhenAgeLessThan0() {
????Person person = new Person();
????catchException(person).setAge(-1);
????assertThat(caughtException()??instanceOf(IllegalArgumentException.class));
????assertThat(caughtException().getMessage()?? containsString("age is invalid"));
????}
????????????????????????????????????????????????????????????
????catch-exception?????????API?????в????
?????????fest-assertion??
????<dependency>
????<groupId>org.easytesting</groupId>
????<artifactId>fest-assert-core</artifactId>
????<version>2.0M10</version>
????</dependency>
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11