TestNG Build-in UI Runner: Set allow-return-values to True

已回答

Background: TestNG feature

TestNG has a property “allow-return-values” that is exposed only within suite.xml file: 

When property is set to FALSE, TestNG will fail at runtime and will not allow execution of tests that return values.

When property is set to TRUE, TestNG will allow execution of tests that return values.

The default value of this property is FALSE.

 

IntelliJ handling of this feature

IntelliJ TestNG build-in UI runner is not setting “allow-return-values” explicitly. When IntelliJ UI runner autogenerates suite.xml file the default value FALSE is used by TestNG.

IntelliJ default runner is not configurable and does not allow setting “allow-return-values” to TRUE.

Setting  “allow-return-values” within suite.xml is not an acceptable/compatible option as it forces user to work with xml file and constantly update it/run_configuration.

 

Expected handling of this feature

IntelliJ default runner should allow user to alter its template for suite.xml and set “allow-return-values” to TRUE. When IntelliJ auto-generates suite.xml it should inject this property.

If IntelliJ decides to auto-generate test suite with this setting being static, static setting should be allowing customers most freedom (“allow-return-values”= TRUE)

 

User Impact

TestNG is used in integration testing, not only unit testing. In large scale projects code re-usability becomes an issue. Having return value can be quite advantageous to methods with dual modality: sometimes method can be executed as test and sometimes as a routine invoked by another test.

1
正式评论

Thanks for a feature suggestion, but unfortunately we have no intention and resources to implement it so far.

In my opinion, it seems that the TestNG feature "allow-return-values" is not directly configuration within IntelliJ Idea's built-in TestNG runner. However, there are a couple of potential workaround you can manually modify the suite.xml file and use a custom TestNG runner. TestNG supports code  reusability through various means like Test Configuration and Parameterization, Test Dependency Management, Test groups and suits, Method Dual Modality. myfedloan 

0

TestNG is a popular testing framework for Java, but it doesn't have a built-in UI runner that directly supports setting the "allow-return-values" property to true. The "allow-return-values" feature is generally associated with TestNG's XML configuration.

If you want to enable the "allow-return-values" feature for TestNG tests, you would typically do so in your testng.xml file, not through a built-in UI runner. Here's an example of how to configure this feature in your testng.xml file:

xmlCopy code

<suite name="MyTestSuite">    <test name="MyTest">        <classes>            <class name="com.example.MyTestClass">                <!-- Set allow-return-values to true -->                <methods>                    <parameter name="org.testng.TestRunner.allow-return-values" value="true" />                </methods>            </class>        </classes>    </test> </suite>

In this example, we have a testng.xml file where we define a suite and a test. Within the test, we specify a class and configure the "allow-return-values" property to be true for specific test methods.

If you are using an external tool or IDE to run your TestNG tests with a UI runner, you may need to check the tool's documentation or settings to see if it allows you to configure TestNG properties, including "allow-return-values." However, this configuration is typically done in the testng.xml file as shown above.

0

My team is well aware that “allow-return-values” can be configured via xml file etc….  But manually tweaking xml does not scale when you have thousands of tests and you want any project user to run any test at any time for any reason (debugging) in IntelliJ. We want to enable this globally once, and just press “Run” button as we do with any other test that returns ‘void’. 

0

@... Please reconsider. We have a lot of IntelliJ (Ultimate) users within company, if you need a certain minimum number of users to “vote” for the feature - I can try to arrange that.

0

请先登录再写评论。