From cd73441786930cfc748b053bdac605355076e03e Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 28 Dec 2019 23:51:53 +0800 Subject: [PATCH] feat: add empyt test --- README.md | 27 +++++++++++++++++++++++++-- core/domain/tbs/tbs_app.go | 25 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bd9b30d..0200ea9 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 0079328..d0fdf16 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, -- GitLab