You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been poking around the test suite for the processors (i.e. src/test/java/sorald/processor), and I've found that there is a whole lot of code duplication. Most of the test classes are borderline identical, and generally follow this pattern:
There is some minor variation in the arguments to Main.main and variable names, but most classes are otherwise semantically identical. If Sorald is to scale with more rules and more tests, I think this must be revamped.
As a solution, I propose that we write a single parameterized test, and keep a directory with "broken" Java files (such as the current src/test/resources directory). Then, each file can be automatically turned into a separate test case. If we for a moment ignore the problem with the variation in command line arguments, a test case file could be named as SomethingInformative_<SONAR_CUBE_KEY>.java, and be used to generate a test case for the rule with key <SONAR_CUBE_KEY> (e.g. EqualsOnAtomicClass_2204.java to test rule 2204).
I have yet to figure out the best solution for the variation in arguments to Main.main, but I'm sure a reasonable solution can be found through some trial and error.
As an example, I've done something similar to this in Spork, an AST-based merge tool. There, I have one directory per test case containing the three input files for the merge, as well as the expected output file as an oracle. Then, source providers that look like this generate input for a handful of test cases that look like this. This gives me hundreds of test cases with very few lines of code, and adding a new test case only requires the addition of new input, there's no additional logic.
I could get to work on this right away. Any thoughts?
The text was updated successfully, but these errors were encountered:
I've been poking around the test suite for the processors (i.e.
src/test/java/sorald/processor
), and I've found that there is a whole lot of code duplication. Most of the test classes are borderline identical, and generally follow this pattern:There is some minor variation in the arguments to
Main.main
and variable names, but most classes are otherwise semantically identical. If Sorald is to scale with more rules and more tests, I think this must be revamped.As a solution, I propose that we write a single parameterized test, and keep a directory with "broken" Java files (such as the current
src/test/resources
directory). Then, each file can be automatically turned into a separate test case. If we for a moment ignore the problem with the variation in command line arguments, a test case file could be named asSomethingInformative_<SONAR_CUBE_KEY>.java
, and be used to generate a test case for the rule with key<SONAR_CUBE_KEY>
(e.g.EqualsOnAtomicClass_2204.java
to test rule 2204).I have yet to figure out the best solution for the variation in arguments to
Main.main
, but I'm sure a reasonable solution can be found through some trial and error.As an example, I've done something similar to this in Spork, an AST-based merge tool. There, I have one directory per test case containing the three input files for the merge, as well as the expected output file as an oracle. Then, source providers that look like this generate input for a handful of test cases that look like this. This gives me hundreds of test cases with very few lines of code, and adding a new test case only requires the addition of new input, there's no additional logic.
I could get to work on this right away. Any thoughts?
The text was updated successfully, but these errors were encountered: