I have a TestNG test that works as expected when run as TestNG Suite in Eclipse, but fails when run via TestNG Ant Task (also via Eclipse). The same test also fails when I run Ant via the command line. The build succeeds, but the test fails with the message:
org.testng.TestNGException:
Parameter 'homepage.title' is required by @Test on method login but has not been marked @Optional or defined
The parameter is defined correctly in my TestNG.xml, and as I mentioned, the same test passes if I run via “Run as TestNG Suite”
Thanks in advance! I hope to be able to help others out as well!
It looks like you define a parameter for the test but not specify a value for it.
There are several ways to solve this.
One would be to specify Parameter annotation and pass parameter in either testng.xml or in through jvm arg:
testng.xml file:
or in build.xml file specify jvmarg property:
The other way, that is suggested by the TestNG, is to annotate parameter with @Optional:
On the additional note, the reason why your build might be passing is whether you tell Ant to fail the build on the test failure. In this case if the build compiles, but there is a test failed, the build will still report “Succeeded” result:
The default value for
haltonfailureproperty is “false”.Please refer to TestNG documentation for more information on parameters and how to use TestNG with Ant.