클래스 파일을 TestNG로만 실행하는 경우 테스트 메소드가 실행되기 전에. 결과 Skipped, failed 또는 passed 테스트 사례 개수 = 0. 스크립트 실행 중에는 오류 또는 예외가 없습니다. 하지만 void 클래스로의 복귀를 변경하면 성공적으로 실행됩니다. 누구든지이 이유를 제안 해 주실 수 있습니까?TestNG 클래스에서 반환 유형이 void가 아니면 테스트가 수행되지 않습니다.
-1
A
답변
0
testng 스위트 파일의 allow-return-values를 testng로 사용하여 테스트로 간주 할 수 있습니다. 일반적으로 테스트의 경우 반환 값은 의미가 없으며 독립 단위로 간주됩니다. 반환 유형을 추가하더라도 allow-return-values가 true이면 Testng에서 무시합니다.
다음은 실제로 작동하는 것을 보여주는 샘플입니다.
import org.testng.Reporter;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestClassSample {
@BeforeMethod
public void beforeMethod() {
Reporter.log("beforeMethod() executed", true);
}
@Test
public String testMethod() {
Reporter.log("testMethod() executed", true);
return null;
}
}
다음은 여기에 해당 제품군의 XML을
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="46765400_Suite" verbose="2" allow-return-values="true">
<test name="46765400_test">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn46765400.TestClassSample"/>
</classes>
</test>
</suite>
을의 코드를 게시하시기 바랍니다 실행 출력을
...
... TestNG 6.12 by Cédric Beust ([email protected])
...
beforeMethod() executed
testMethod() executed
PASSED: testMethod
===============================================
46765400_test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
46765400_Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
+0
도움을 주셔서 감사합니다. –
을합니다. –
디버깅 도움말을 찾는 질문 ("**이 코드가 작동하지 않는 이유는 무엇입니까? **")에는 원하는 동작, * 특정 문제 또는 오류 및 해당 문제를 재현하는 데 필요한 가장 짧은 코드가 ** 포함되어야합니다. ** . ** 명확한 문제 설명이없는 질문 **은 다른 독자에게 유용하지 않습니다. 참조 : [mcve]. – JeffC