提交 3bc9a913 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

support jacoco

上级 1352a079
......@@ -82,6 +82,8 @@ func main() {
flagSet.StringVar(&unitTestTool, "unitTestTool", "", "")
flagSet.StringVar(&unitBuildTool, "unitBuildTool", "", "")
flagSet.StringVar(&commConsts.JacocoReport, "jacocoReport", "", "")
flagSet.StringVar(&keywords, "k", "", "")
flagSet.StringVar(&keywords, "keywords", "", "")
......@@ -265,6 +267,9 @@ func runUnitTest(args []string) {
if commConsts.AllureReportDir != "" {
start = start + 2
}
if commConsts.JacocoReport != "" {
start = start + 2
}
if unitTestTool != "" {
start = start + 2
}
......
......@@ -27,6 +27,7 @@ var (
UnitBuildTool BuildTool
UnitTestTool TestTool
AllureReportDir string
JacocoReport string
ProductId string
ZenTaoVersion string
......
package commDomain
type JacocoReport struct {
Sessioninfo JacocoSessioninfo `xml:"sessioninfo"`
Package JacocoPackage `xml:"package"`
Counter []JacocoCounter `xml:"counter"`
Name string `xml:"name,attr"`
}
type JacocoCounter struct {
Type Type `xml:"type,attr"`
Missed string `xml:"missed,attr"`
Covered string `xml:"covered,attr"`
}
type JacocoPackage struct {
Class JacocoClassClass `xml:"class"`
Sourcefile JacocoSourcefile `xml:"sourcefile"`
Counter []JacocoCounter `xml:"counter"`
Name string `xml:"name,attr"`
}
type JacocoClassClass struct {
Method []JacocoMethodElement `xml:"method"`
Counter []JacocoCounter `xml:"counter"`
Name string `xml:"name,attr"`
Sourcefilename string `xml:"sourcefilename,attr"`
}
type JacocoMethodElement struct {
Counter []JacocoCounter `xml:"counter"`
Name string `xml:"name,attr"`
Desc string `xml:"desc,attr"`
Line string `xml:"line,attr"`
}
type JacocoSourcefile struct {
Line []JacocoLineElement `xml:"line"`
Counter []JacocoCounter `xml:"counter"`
Name string `xml:"name,attr"`
}
type JacocoLineElement struct {
Nr string `xml:"nr,attr"`
Mi string `xml:"mi,attr"`
Ci string `xml:"ci,attr"`
MB string `xml:"mb,attr"`
Cb string `xml:"cb,attr"`
}
type JacocoSessioninfo struct {
ID string `xml:"id,attr"`
Start string `xml:"start,attr"`
Dump string `xml:"dump,attr"`
}
type Type string
const (
Branch Type = "BRANCH"
Class Type = "CLASS"
Complexity Type = "COMPLEXITY"
Instruction Type = "INSTRUCTION"
Line Type = "LINE"
Method Type = "METHOD"
)
......@@ -35,6 +35,7 @@ func Exec(ch chan int, req serverDomain.ExecReq, msg *websocket.Message) (
ExecUnit(ch, testSet, msg)
}
}() // for defer
}
return
......
package execHelper
import (
"encoding/xml"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain "github.com/easysoft/zentaoatf/internal/pkg/domain"
dateUtils "github.com/easysoft/zentaoatf/pkg/lib/date"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/fatih/color"
"time"
)
const (
Tmpl = `Counter Missed Covered
------------------------------------------
%11s %s %s
%11s %s %s
%11s %s %s
%11s %s %s
%11s %s %s
%11s %s %s
`
)
func GenJacocoCovReport() (report commDomain.JacocoReport) {
content := fileUtils.ReadFileBuf(commConsts.JacocoReport)
xml.Unmarshal(content, &report)
var params []interface{}
for _, counter := range report.Counter {
params = append(params, string(counter.Type))
params = append(params, counter.Missed)
params = append(params, counter.Covered)
}
title := i118Utils.Sprintf("jacoco_report")
msg := dateUtils.DateTimeStr(time.Now()) + " " + title + " \n" + i118Utils.Sprintf(Tmpl, params...)
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
return
}
......@@ -41,7 +41,7 @@ func ExecUnit(ch chan int,
iris.Map{"key": key, "status": "start"}, wsMsg)
}
//deal with -allureReportDir param
//deal with -allureReportDir param
arr := strings.Split(req.Cmd, " ")
if len(arr) > 1 && strings.TrimSpace(arr[0]) == "-allureReportDir" {
commConsts.AllureReportDir = arr[1]
......@@ -74,6 +74,11 @@ func ExecUnit(ch chan int,
// gen report
report := GenUnitTestReport(req, startTime.Unix(), entTime.Unix(), ch, wsMsg)
// dealwith jacoco report
if commConsts.JacocoReport != "" {
GenJacocoCovReport()
}
// submit result
if req.SubmitResult && (report.FuncResult != nil || report.UnitResult != nil) {
configDir := req.WorkspacePath
......
......@@ -726,6 +726,10 @@
{
"id": "pls_check_zentao_url",
"translation": "%s, Zentao version '%s'.\n Please use above OpenSource 17.0, Biz 7.0, Max 3.1 version, or you may install RestAPI plugin according to UserManual section 4.4."
},
{
"id": "jacoco_report",
"translation": "Jacoco Coverage Report"
}
]
}
......@@ -714,6 +714,10 @@
{
"id": "pls_check_zentao_url",
"translation": "%s,当前禅道版本'%s'。\n请确认您使用了禅道开源17.0、企业7.0、旗舰3.1以上版本,或已按照用户手册4.4小节成功安装RestAPI插件。"
},
{
"id": "jacoco_report",
"translation": "Jacoco覆盖率报告"
}
]
}
<report name="ci_test_jcoco">
<sessioninfo id="MacBook-Pro.local-326fb78a" start="1682494760900" dump="1682494762314"/>
<package name="com/deeptest/sample/jcoco">
<class name="com/deeptest/sample/jcoco/Count" sourcefilename="Count.java">
<method name="&lt;init&gt;" desc="()V" line="3">
<counter type="INSTRUCTION" missed="0" covered="3"/>
<counter type="LINE" missed="0" covered="1"/>
<counter type="COMPLEXITY" missed="0" covered="1"/>
<counter type="METHOD" missed="0" covered="1"/>
</method>
<method name="add" desc="(II)I" line="5">
<counter type="INSTRUCTION" missed="1" covered="10"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="1" covered="4"/>
<counter type="COMPLEXITY" missed="1" covered="1"/>
<counter type="METHOD" missed="0" covered="1"/>
</method>
<method name="sub" desc="(II)I" line="16">
<counter type="INSTRUCTION" missed="4" covered="0"/>
<counter type="LINE" missed="1" covered="0"/>
<counter type="COMPLEXITY" missed="1" covered="0"/>
<counter type="METHOD" missed="1" covered="0"/>
</method>
<method name="div" desc="(II)I" line="20">
<counter type="INSTRUCTION" missed="4" covered="0"/>
<counter type="LINE" missed="1" covered="0"/>
<counter type="COMPLEXITY" missed="1" covered="0"/>
<counter type="METHOD" missed="1" covered="0"/>
</method>
<counter type="INSTRUCTION" missed="9" covered="13"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="3" covered="5"/>
<counter type="COMPLEXITY" missed="3" covered="2"/>
<counter type="METHOD" missed="2" covered="2"/>
<counter type="CLASS" missed="0" covered="1"/>
</class>
<sourcefile name="Count.java">
<line nr="3" mi="0" ci="3" mb="0" cb="0"/>
<line nr="5" mi="0" ci="2" mb="0" cb="0"/>
<line nr="6" mi="0" ci="2" mb="1" cb="1"/>
<line nr="7" mi="0" ci="2" mb="0" cb="0"/>
<line nr="9" mi="1" ci="0" mb="0" cb="0"/>
<line nr="12" mi="0" ci="4" mb="0" cb="0"/>
<line nr="16" mi="4" ci="0" mb="0" cb="0"/>
<line nr="20" mi="4" ci="0" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="9" covered="13"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="3" covered="5"/>
<counter type="COMPLEXITY" missed="3" covered="2"/>
<counter type="METHOD" missed="2" covered="2"/>
<counter type="CLASS" missed="0" covered="1"/>
</sourcefile>
<counter type="INSTRUCTION" missed="9" covered="13"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="3" covered="5"/>
<counter type="COMPLEXITY" missed="3" covered="2"/>
<counter type="METHOD" missed="2" covered="2"/>
<counter type="CLASS" missed="0" covered="1"/>
</package>
<counter type="INSTRUCTION" missed="9" covered="13"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="3" covered="5"/>
<counter type="COMPLEXITY" missed="3" covered="2"/>
<counter type="METHOD" missed="2" covered="2"/>
<counter type="CLASS" missed="0" covered="1"/>
</report>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册