TestNG
的組名稱經常被硬編碼並可能降低軟件質量。我想知道如何防止硬編碼組名稱。防止TestNG硬編碼組名稱
在TestCase.java中,是的,我可以使用靜態最終字符串,而不是像@JavaSoftwareTester在this post中詢問的那樣。
public class TestType {
private static final String GROUP_A = "GroupA";
private static final String GROUP_B = "GroupB"
/**
* Avoid instantiation
*/
private TestType() {
}
}
但是,看來這最後的字符串不能在testng.xml文件中使用,如:
<groups>
<run>
<!-- I don't want hard coded -->
<include name = "GroupA" />
<!-- but this is incorrect -->
<include name = TestType.GROUP_A />
</run>
</groups>
總結:我想,以防止硬編碼的組名,但我無法找到合適的機制。請善意表明如何解決這個問題。
XML是文本,而不是代碼,因此它無法引用一個XML描述Java代碼。 – juherr