Java 从属性文件读取TestNG注释参数值

Java 从属性文件读取TestNG注释参数值,java,properties,testng,Java,Properties,Testng,我正在使用TestNG。我需要从属性文件中读取“invocationCount”的值。 我在下面尝试了,但得到了编译错误。有人能帮我吗 public static final int TC=Integer.parseInt(p.getProperty("threadcount")); @Test(threadPoolSize=10,invocationCount=TC) public void someMethod { } 编译错误:注释属性Test.invocationCount的值必须是

我正在使用TestNG。我需要从
属性
文件中读取
“invocationCount”
的值。 我在下面尝试了,但得到了编译错误。有人能帮我吗

public static final int TC=Integer.parseInt(p.getProperty("threadcount"));

@Test(threadPoolSize=10,invocationCount=TC)
public void someMethod { }

编译错误:注释属性Test.invocationCount的值必须是常量表达式

Srikanth,您需要实现Testng公开的IANotationTransformer。您可以编写代码来读取属性文件,并设置在transform方法实现中调用的当前测试的调用计数。举一个例子


在测试中,将Iannotationtransformer的实现指定为监听器,可以在suite.xml中,也可以在类级别使用@Listeners annotation,正如它所说的那样,Java中的注释值必须是常量表达式…然后,无法读取属性文件吗?请查看文档的5.15:-您可以执行类似于
annotation.setInvocationCount(TC)的操作。你能详细说明一下吗?我需要把上面的语句放在哪里?放在方法里面?