Skip to content

Test Smell: it is not a good test practice to use the loop in the test #1038

Open

Description

@TestSmell

Hi!

We notice that you use the loop structure in your test cases.
For example, testQualityScoresIntArray() in FastqToolsTest.java
截屏2022-08-17 下午5 17 26

However, using the loop in test cases is not a good test practice.
We analyzed the relevant Stack Overflow posts and summarized four potential negatives it brings:

  1. Loops make the test case more complex
  2. In most cases, a loop can be replaced with a data-driven test that is more readable.
  3. Loops break the assert-for-one-thing thumb rule. I don't mean a single assert statement.
  4. When a test fails, knowing the reason is more complicated.

Solution:
To avoid using the loop in the test, JUnit provides an annotation (i.e., @ParameteredTest), enabling a test case to run multiple times with different parameters.
We provide a usage example here:
image

Activity

  1. josemduarte commented on Aug 26, 2022

    @josemduarte
    Contributor

    Good point, thanks! Would you be able to provide a pull request?

  2. tmrpavan commented on Apr 26, 2023

    @tmrpavan
    Contributor

    @josemduarte I would like to work on this. We are using Junit4 is there any chance to migrate Junit5. So this type of test case are easy to write in Junit5

  3. josemduarte commented on Apr 26, 2023

    @josemduarte
    Contributor

    Yes we have in fact converted some tests to junit5 and the agreement is that new tests should be junit5.

  4. tmrpavan commented on Apr 27, 2023

    @tmrpavan
    Contributor

    can you assign this issue to me. I will work on this

  5. arkanar611 commented on May 27, 2026

    @arkanar611

    I've created two merge requests for the genome module:
    this one #1125 includes migration to junit5 only for the FastqToolsTest.java
    And this one #1126 migrates all genome module tests to junit5

    MRs can be reviewed separately or we can merge only the last one because it includes all changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions