문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
java:junit [2013/11/14 15:26] kwon37xi |
java:junit [2015/11/21 13:26] (현재) kwon37xi |
||
---|---|---|---|
줄 3: | 줄 3: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
- | ==== Parameterized Test ==== | + | ===== Parameterized Test ===== |
* '' | * '' | ||
* '' | * '' | ||
줄 12: | 줄 13: | ||
@RunWith(Parameterized.class) | @RunWith(Parameterized.class) | ||
class MyParameterizedClassTest { | class MyParameterizedClassTest { | ||
- | private int multiplier; | + | |
- | public MyParameterizedClassTest(int testParameter) { | + | |
- | this.multiplier = testParameter; | + | this.multiplier = testParameter; |
- | } | + | } |
- | // creates the test data | + | |
- | @Parameters | + | |
- | public static java.util.Collection< | + | public static java.util.Collection< |
- | Object[][] data = new Object[][] { {1}, {5}, {121}}; | + | Object[][] data = new Object[][] { {1}, {5}, {121}}; |
- | return Arrays.asList(data); | + | return Arrays.asList(data); |
- | } | + | |
- | @Test | + | |
- | public void testMultiplyException() { | + | public void testMultiplyException() { |
- | MyClass tester = new MyClass(); | + | MyClass tester = new MyClass(); |
- | assertEquals(" | + | assertEquals(" |
- | } | + | |
} | } | ||
</ | </ | ||
- | ===== Exception Rule ===== | + | ===== Assume |
- | * 예외 발생 | + | '' |
<code java> | <code java> | ||
- | | + | @Before |
- | public | + | |
+ | org.junit.Assume.assumeTrue(someCondition()); | ||
+ | // rest of setup. | ||
+ | } | ||
+ | // someCondition() == true 일 때만 테스트들이 실행된다. | ||
+ | </ | ||
- | | + | |
- | | + | |
- | // 발생할 예외에 대한 조건 기술 | + | ===== 테스트 실행 순서 ===== |
- | exception.expect(IllegalArgumentException.class); | + | |
- | | + | * [[http://examples.javacodegeeks.com/ |
- | + | ||
- | ClassToBeTested t = new ClassToBeTested(); | + | ===== IntelliJ Live Template for try/catch JUnit/ |
- | | + | * abbrevication : '' |
- | } | + | * '' |
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * Template text : <code java> | ||
+ | try { | ||
+ | | ||
+ | } catch ($EXCEPTION$ ex) { | ||
+ | | ||
+ | ex.getMessage(), org.hamcrest.CoreMatchers.is(" | ||
+ | } | ||
</ | </ | ||
+ | |||
+ | ===== Plugins ===== | ||
+ | * [[https:// | ||