Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose test smell threshold set to 123? #3

Open
ishepard opened this issue Jan 14, 2020 · 2 comments
Open

Verbose test smell threshold set to 123? #3

ishepard opened this issue Jan 14, 2020 · 2 comments

Comments

@ishepard
Copy link

Hi! Thanks for the tool!
I was looking at the threshold of Verbose Test, and it's currently set to 123 statements. I think this is an error, it seems waaay to high, and also it's kind of a magic number (first 3 numbers of the keyboard). Is it a leftover? What's the correct threshold?

@mkaouer
Copy link
Contributor

mkaouer commented Jan 15, 2020

Hi Davide,
Thank you for taking the time to try the tool.
Indeed any threshold can be definitely optimized either by making it user-defined or by using intelligent (learning from instances labeled by human annotators).
@shehan How did we initialize this threhold?

@jose
Copy link

jose commented Nov 21, 2024

Yep, the implementation of the VerboseTest sounds odd. Here my suggestion on how it could be fixed:

diff --git a/src/main/java/testsmell/smell/VerboseTest.java b/src/main/java/testsmell/smell/VerboseTest.java
index 13b9344..94ae202 100644
--- a/src/main/java/testsmell/smell/VerboseTest.java
+++ b/src/main/java/testsmell/smell/VerboseTest.java
@@ -40,9 +40,7 @@ public class VerboseTest extends AbstractSmell {
     }

     private class ClassVisitor extends VoidVisitorAdapter<Void> {
-        final int MAX_STATEMENTS = 123;
         private MethodDeclaration currentMethod = null;
-        private int verboseCount = 0;
         TestMethod testMethod;

         // examine all methods in the test class
@@ -54,23 +52,21 @@ public class VerboseTest extends AbstractSmell {
                 testMethod.setSmell(false); //default value is false (i.e. no smell)

                 //method should not be abstract
+                int numberOfStatements = 0;
                 if (!currentMethod.isAbstract()) {
                     if (currentMethod.getBody().isPresent()) {
                         //get the total number of statements contained in the method
-                        if (currentMethod.getBody().get().getStatements().size() >= MAX_STATEMENTS) {
-                            verboseCount++;
-                        }
+                        numberOfStatements = currentMethod.getBody().get().getStatements().size();
                     }
                 }
-                boolean isSmelly = verboseCount > thresholds.getVerboseTest();
+                boolean isSmelly = numberOfStatements > thresholds.getVerboseTest();
                 testMethod.setSmell(isSmelly);
-                testMethod.addDataItem("VerboseCount", String.valueOf(verboseCount));
+                testMethod.addDataItem("VerboseCount", String.valueOf(isSmelly ? 1 : 0));

                 smellyElementsSet.add(testMethod);

                 //reset values for next method
                 currentMethod = null;
-                verboseCount = 0;
             }
         }
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants