diff --git a/README.md b/README.md index bd9b30d7e9dae5bd44df4ddff603275660bf7f91..0200ea9860adc0989361539f5d75625a4c5261e5 100644 --- a/README.md +++ b/README.md @@ -115,14 +115,12 @@ Examples Result: "File": "examples/api/BookController.java", "BS": "dataClass" } - ... ], "lazyElement": [ { "File": "examples/api/model/BookRepresentaion.java", "BS": "lazyElement" } - ... ] } ``` @@ -437,6 +435,31 @@ results: +--------+------------------+--------------------------------+ ``` +### Test Bad Smells + +``` +coca tbs +``` + +results + +```json +[ + { + "FileName": "_fixtures/tbs/code/EmptyTest.java", + "Type": "EmptyTest", + "Description": "", + "Line": 0 + }, + { + "FileName": "_fixtures/tbs/code/IgnoreTest.java", + "Type": "IgnoreTest", + "Description": "", + "Line": 0 + } +] +``` + ## Dev Install Go diff --git a/core/domain/tbs/tbs_app.go b/core/domain/tbs/tbs_app.go index 0079328a1333f66ac38d55055dc6f1068279167c..d0fdf164eaa8d448cb0df30d51e06a2ded35f800 100644 --- a/core/domain/tbs/tbs_app.go +++ b/core/domain/tbs/tbs_app.go @@ -31,18 +31,37 @@ func (a TbsApp) AnalysisPath(deps []models.JClassNode, identifiersMap map[string // TODO refactoring identify & annotation for _, method := range clz.Methods { fullName := clz.Package + "." + clz.Class + "." + method.Name - checkIgnoreTest(clz, identMethodMap[fullName], &results) + checkIgnoreTest(clz.Path, identMethodMap[fullName], &results) + checkEmptyTest(clz.Path, identMethodMap[fullName], method, &results) } } return results } -func checkIgnoreTest(clz models.JClassNode, method models.JMethod, results *[]TestBadSmell) { +func checkEmptyTest(path string, iMethod models.JMethod, cMethod models.JMethod, results *[]TestBadSmell) { + for _, annotation := range iMethod.Annotations { + if annotation.QualifiedName == "Test" { + if len(cMethod.MethodCalls) <= 1 { + tbs := *&TestBadSmell{ + FileName: path, + Type: "EmptyTest", + Description: "", + Line: 0, + } + + *results = append(*results, tbs) + } + } + } + +} + +func checkIgnoreTest(clzPath string, method models.JMethod, results *[]TestBadSmell) { for _, annotation := range method.Annotations { if annotation.QualifiedName == "Ignore" { tbs := *&TestBadSmell{ - FileName: clz.Path, + FileName: clzPath, Type: "IgnoreTest", Description: "", Line: 0,