testng icon indicating copy to clipboard operation
testng copied to clipboard

Test Smell: it is not a good practice to write a return statement in the test case

Open TestSmell opened this issue 3 years ago • 5 comments

Hi! I notice that you write a test case with a return statement. For example, image

It is not a good idea to write the return statement in your test case based on the definition of the test case. So I would like to know if is it really a useful test case? And no assertion is in this test case. Maybe I think you should remove this test case from your test code. Thanks.

TestSmell avatar Aug 29 '22 08:08 TestSmell

Right. It may be one of the first tests when the current best practices didn't exist.

The cannot be removed because I think there is not yet a warning against this practice.

You can propose a pull request that adds a warning message. You can add a "for removal" tag to related tests.

juherr avatar Aug 29 '22 16:08 juherr

@juherr can I take this?

rajasu8 avatar Aug 08 '23 17:08 rajasu8

@rajasu8 sure. Go ahead 👍

juherr avatar Aug 08 '23 18:08 juherr

Hi @juherr,

I would like to work on this. Do you know how I could test the changes? When I update a test method signature and the code to return something I am getting an error "> No tests found for given includes: [NoPackageTest.test](--tests filter)". Wondering if this has been fixed already and if the tests with a return type are not getting picked up by the filter

IsaakKrut avatar Jul 08 '24 23:07 IsaakKrut

@IsaakKrut I am uncertain if you will be able to test the modification.

The desired outcome is for a warning message to be displayed if the test methods contain a return statement. Furthermore, it should be possible to tag tests by a specific group or fix all the tests that currently have a return statement in our test suite.

To validate that the intended function is working properly, only one test case should have an explicit return value.

While I am not familiar with your testing methods, this is expected to function correctly when the test suite is executed using Gradle.

juherr avatar Jul 09 '24 08:07 juherr