TestNG는 verify 문을 지원하지 않지만 쉽게 구현할 수 있습니다. 가장 간단한 방법은 아래처럼 시험 방법에 자바의 StringBuffer를 사용하는 것입니다
해당 인터페이스에서 두 가지 방법을 구현해야 어디 TestNG를의 IInvokedMethodListener 인터페이스를 사용할 수있는 고급 구현을 위해
@Test
public void verifyTest(){
/* buffer to hold your errors */
StringBuffer errorBuffer = new StringBuffer();
/* verification 1 */
try{
Assert.assertEquals("value1", "value!");
}catch(AssertionError e){
errorBuffer.append(e.getMessage() + "\n");
}
/* verification 2 */
try{
Assert.assertEquals("value2", "value!");
}catch(AssertionError e){
errorBuffer.append(e.getMessage());
}
if(errorBuffer.length() > 0){
throw new AssertionError(errorBuffer.toString());
}
}
,
public class TestMethodListener implements IInvokedMethodListener{
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
if(method.isTestMethod()){
/* create new error buffer object */
}
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
if(method.isTestMethod()){
/* process your test result for verification errors stored in error buffer
* and modify your testResult object accordingly
*/
}
}
}
대부분의 경우 고급 구현을 위해 갈 필요가 없습니다. 간단한 StringBuffer 작동합니다. 그러나 테스트에서 자주 verify 문을 사용하려면 IInvokedMethodListener를 구현하는 것이 타당합니다. 고급 구현에 관심이 있다면이 블로그를 확인하십시오. https://muthutechno.wordpress.com/2015/01/26/implementing-verify-statements-for-testng-framework/
어떤 테스트 프레임 워크를 사용 했습니까? TestNG 또는 JUnit입니까? –