1

I am beginner to TestNG. I about test method in official TestNG documentation. I am not clear with the use of allow-return-values="true" can any one explain it briefly with example. I did one example I didn't get way the way of using,

This is my .xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="newSuite" parallel="methods" thread-count="5" allow-return-values="true">
<parameter name="browser" value="Firefox"></parameter>
<test name="dataprovider" allow-return-values="true">
   <classes>
      <class name="com.tets.SampleTest"></class>
   </classes>
</test>
</suite>

and my test class is as follows,

public class SampleTest {

@AfterMethod
public void teardown(Object returnValueFromTest){
    //inspect returnValueFromTest and perform necessary clean up.
}


@Test
public String testEventGeneration(){
    //generate event

    //returning generated e vent id.
    return "E1234";

}

@Test
public String testMarketGeneration(){
    //generate market

    //returning generated market.
    return "hai";
}}

How and where can I get the return value from testMarketGeneration test method ?

1 Answer 1

1

The option 'allow-return-values' is not meant to test the return value "hai". It is meant to allow @Test annotation on methods that have return values.

By default TestNG follows best practices for unit testing, which means a unit test method should not have a return value. However sometimes you want to add the @Test annotation to a method with a return value. If you do not specify 'allow-return-values' in your Suite configuration TestNG will print out a warning and will not run the method as tests.

The warning TestNG gives is something like:

Method public java.util.List a.B.getC(java.util.List) has a @Test annotation but also a return value: ignoring it. Use 'suite allow-return-values="true"' to fix this

The only useful example of allowing return values I have found so far is when your test class implements a certain interface and you want to test all interface methods by adding @Test annotations.

See http://testng.org/doc/documentation-main.html for the real documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.