Skip to content

Commit 1cf209d

Browse files
committed
added NUnit2 report data
fixed NUnit2Handler
1 parent 796a98e commit 1cf209d

File tree

5 files changed

+66
-63
lines changed

5 files changed

+66
-63
lines changed

src/main/java/main/model/db/imports/SAXHandlers/NUnitV2Handler.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,40 @@ public void endDocument() {
4444
@Override
4545
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
4646
currentElement = qName;
47-
if(qName.equals("test-results")){
47+
if (qName.equals("test-results")) {
4848
try {
4949
testRun.setFinish_time(convertToDate(attributes.getValue("date"), attributes.getValue("time")));
5050
} catch (ParseException e) {
5151
e.printStackTrace();
5252
}
53-
}
54-
else if (qName.equals("environment")) {
53+
} else if (qName.equals("environment")) {
5554
testRun.setExecution_environment(attributes.getValue("machine-name"));
5655
testRun.setAuthor(String.format("%s\\%s", attributes.getValue("user-domain"), attributes.getValue("user")));
5756

58-
}
59-
else if (qName.equals("test-suite") && attributes.getValue("type").equals("TestSuite") && strTime == null) {
57+
} else if (qName.equals("test-suite")
58+
&& (attributes.getValue("type").equals("TestSuite") || attributes.getValue("type").equals("Assembly"))
59+
&& strTime == null) {
6060

6161
calendar.setTime(testRun.getFinish_time());
6262
strTime = attributes.getValue("time");
63-
milliTime = Integer.parseInt(strTime.replaceAll("\\.",""));
63+
milliTime = Integer.parseInt(strTime.replaceAll("\\.", ""));
6464
calendar.add(Calendar.MILLISECOND, -milliTime);
6565
testRun.setStart_time(calendar.getTime());
6666
currentTimeSlot = testRun.getStart_time();
67-
} else if(qName.equals("test-suite") && attributes.getValue("type").equals("TestSuite")
68-
&& strTime.equals(attributes.getValue("time"))){
67+
} else if (qName.equals("test-suite") && attributes.getValue("type").equals("TestSuite")
68+
&& strTime.equals(attributes.getValue("time"))) {
6969
testSuite.setName(attributes.getValue("name"));
70-
} else if(qName.equals("test-case")) {
70+
} else if (qName.equals("test-case")) {
7171
isTestCaseClose = false;
7272
test.setName(attributes.getValue("name"));
7373
result.setStart_date(currentTimeSlot);
7474
calendar.setTime(currentTimeSlot);
75-
milliTime = Integer.parseInt(attributes.getValue("time").replaceAll("\\.",""));
75+
milliTime = Integer.parseInt(attributes.getValue("time").replaceAll("\\.", ""));
7676
calendar.add(Calendar.MILLISECOND, milliTime);
7777
currentTimeSlot = calendar.getTime();
7878
result.setFinish_date(currentTimeSlot);
7979

80-
if(attributes.getValue("success").equals("False")){
80+
if (attributes.getValue("success").equals("False")) {
8181
isTestFailed = true;
8282
}
8383

@@ -96,7 +96,7 @@ public void endElement(String uri, String localName, String qName) {
9696
tests.add(test);
9797
test = new TestDto();
9898
result.setInternalTestId(test.getName());
99-
if(result.getFail_reason() != null && result.getFail_reason().equals("$blank")) result.setFail_reason("");
99+
if (result.getFail_reason() != null && result.getFail_reason().equals("$blank")) result.setFail_reason("");
100100
results.add(result);
101101
result = new TestResultDto();
102102
result.setFail_reason("$blank");
@@ -105,7 +105,7 @@ public void endElement(String uri, String localName, String qName) {
105105

106106
@Override
107107
public void characters(char[] ch, int start, int length) {
108-
String value = new String(ch,start,length);
108+
String value = new String(ch, start, length);
109109
if (isTestFailed) {
110110
if (currentElement.equals("message")) {
111111
String res = result.getFail_reason();
@@ -129,7 +129,7 @@ private Date convertToDate(String dateString, String timeString) throws ParseExc
129129
return format.parse(date);
130130
}
131131

132-
private ResultStatus getStatus(String status){
132+
private ResultStatus getStatus(String status) {
133133
switch (status) {
134134
case "Success":
135135
return PASSED;
@@ -141,19 +141,19 @@ private ResultStatus getStatus(String status){
141141
}
142142
}
143143

144-
public TestSuiteDto getTestSuite(){
144+
public TestSuiteDto getTestSuite() {
145145
return testSuite;
146146
}
147147

148-
public TestRunDto getTestRun(){
148+
public TestRunDto getTestRun() {
149149
return testRun;
150150
}
151151

152-
public List<TestDto> getTests(){
152+
public List<TestDto> getTests() {
153153
return tests;
154154
}
155155

156-
public List<TestResultDto> getTestResults(){
156+
public List<TestResultDto> getTestResults() {
157157
return results;
158158
}
159159
}

src/test/resources/reports/NUnit2/NUnit2.xml

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
11
<?xml version="1.0" encoding="utf-8" standalone="no"?>
22
<!--This file represents the results of running a test suite-->
3-
<test-results name="D:\framework\test\nunit\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" total="4" errors="0" failures="2" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2020-03-17" time="09:56:36">
4-
<environment nunit-version="3.6.0.0" clr-version="4.0.30319.42000" os-version="Microsoft Windows NT 10.0.18363.0" platform="Win32NT" cwd="D:\framework\test\nunit\UnitTestProject1\UnitTestProject1\bin\Debug" machine-name="KNYSHS" user="s.knysh" user-domain="ITRANSITION" />
3+
<test-results name="D:\bin\Debug\Core.dll" total="1" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2020-03-18" time="07:16:58">
4+
<environment nunit-version="3.6.0.0" clr-version="4.0.30319.42000" os-version="Microsoft Windows NT 10.0.18363.0" platform="Win32NT" cwd="D:\bin\Debug" machine-name="user" user="user" user-domain="domain" />
55
<culture-info current-culture="ru-RU" current-uiculture="en-US" />
6-
<test-suite type="Assembly" name="D:\framework\test\nunit\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" executed="True" result="Failure" success="False" time="0.086" asserts="0">
6+
<test-suite type="Assembly" name="D:\bin\Debug\Core.dll" executed="True" result="Success" success="True" time="34" asserts="0">
77
<properties>
8-
<property name="_PID" value="21528" />
8+
<property name="_PID" value="22312" />
99
<property name="_APPDOMAIN" value="domain-" />
1010
</properties>
11-
<failure>
12-
<message><![CDATA[One or more child tests had errors]]></message>
13-
<stack-trace />
14-
</failure>
1511
<results>
16-
<test-suite type="Namespace" name="UnitTestProject1" executed="True" result="Failure" success="False" time="0.079" asserts="0">
17-
<failure>
18-
<message><![CDATA[One or more child tests had errors]]></message>
19-
<stack-trace />
20-
</failure>
12+
<test-suite type="TestSuite" name="SUITENAME" executed="True" result="Success" success="True" time="33" asserts="0">
2113
<results>
22-
<test-suite type="TestFixture" name="UnitTest1" executed="True" result="Failure" success="False" time="0.059" asserts="0">
23-
<failure>
24-
<message><![CDATA[One or more child tests had errors]]></message>
25-
<stack-trace />
26-
</failure>
14+
<test-suite type="TestSuite" name="Gherkin" executed="True" result="Success" success="True" time="33" asserts="0">
2715
<results>
28-
<test-case name="UnitTestProject1.UnitTest1.TestMethod1" executed="True" result="Success" success="True" time="0.018" asserts="0" />
29-
<test-case name="UnitTestProject1.UnitTest1.TestMethod2" executed="True" result="Failure" success="False" time="0.032" asserts="0">
30-
<failure>
31-
<message><![CDATA[TestMethod2]]></message>
32-
<stack-trace><![CDATA[ at NUnit.Framework.Assert.Fail(String message, Object[] args)
33-
at UnitTestProject1.UnitTest1.TestMethod2() in D:\framework\test\nunit\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 19]]></stack-trace>
34-
</failure>
35-
</test-case>
36-
</results>
37-
</test-suite>
38-
<test-suite type="TestFixture" name="UnitTest2" executed="True" result="Failure" success="False" time="0.017" asserts="0">
39-
<failure>
40-
<message><![CDATA[One or more child tests had errors]]></message>
41-
<stack-trace />
42-
</failure>
43-
<results>
44-
<test-case name="UnitTestProject1.UnitTest2.TestMethod3" executed="True" result="Success" success="True" time="0.010" asserts="0" />
45-
<test-case name="UnitTestProject1.UnitTest2.TestMethod4" executed="True" result="Failure" success="False" time="0.006" asserts="0">
46-
<failure>
47-
<message><![CDATA[TestMethod2]]></message>
48-
<stack-trace><![CDATA[ at NUnit.Framework.Assert.Fail(String message, Object[] args)
49-
at UnitTestProject1.UnitTest2.TestMethod4() in D:\framework\test\nunit\UnitTestProject1\UnitTestProject1\UnitTest2.cs:line 19]]></stack-trace>
50-
</failure>
51-
</test-case>
16+
<test-suite type="TestSuite" name="Features" executed="True" result="Success" success="True" time="33" asserts="0">
17+
<results>
18+
<test-suite type="TestSuite" name="Core" executed="True" result="Success" success="True" time="33" asserts="0">
19+
<results>
20+
<test-suite type="TestSuite" name="CORE" executed="True" result="Success" success="True" time="33" asserts="0">
21+
<results>
22+
<test-suite type="TestSuite" name="Administration" executed="True" result="Success" success="True" time="33" asserts="0">
23+
<results>
24+
<test-suite type="TestSuite" name="AdministrationMenu" executed="True" result="Success" success="True" time="33" asserts="0">
25+
<results>
26+
<test-suite type="TestSuite" name="ApplicationSettings" executed="True" result="Success" success="True" time="33" asserts="0">
27+
<results>
28+
<test-suite type="TestFixture" name="CORETC_1540Feature" description="CORETC-1540" executed="True" result="Success" success="True" time="33" asserts="0">
29+
<properties>
30+
<property name="Description" value="CORETC-1540" />
31+
</properties>
32+
<results>
33+
<test-case name="SUITENAME.Gherkin.Features.Core.CORE.Administration.AdministrationMenu.ApplicationSettings.CORETC_1540Feature.CORETC_1540_Administration" description="CORETC-1540_Administration_section can be opened" executed="True" result="Success" success="True" time="32" asserts="0">
34+
<categories>
35+
<category name="PRODUCT_MAT" />
36+
</categories>
37+
<properties>
38+
<property name="Description" value="CORETC-1540_Administration_section can be opened" />
39+
</properties>
40+
</test-case>
41+
</results>
42+
</test-suite>
43+
</results>
44+
</test-suite>
45+
</results>
46+
</test-suite>
47+
</results>
48+
</test-suite>
49+
</results>
50+
</test-suite>
51+
</results>
52+
</test-suite>
53+
</results>
54+
</test-suite>
5255
</results>
5356
</test-suite>
5457
</results>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Setup exception."},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Setup exception."},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Setup exception."},{"final_result_id":3,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":"My ignore reason"},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":1,"log":" at Example.Tests.Class2.Test2() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class2.cs:line 26\n","start_date":1561543136000,"finish_date":1561543136000,"fail_reason":"Assertion:\r\nMy warn message"},{"final_result_id":1,"log":" at Example.Tests.Class2.Test3() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class2.cs:line 32\n at Example.Tests.Class2.Test3() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class2.cs:line 32\n","start_date":1561543136000,"finish_date":1561543136000,"fail_reason":"Assertion:\r\ntest failed."},{"final_result_id":1,"log":" at Example.Tests.Class2.Test3FailedWithoutMessage() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class2.cs:line 38\n at Example.Tests.Class2.Test3FailedWithoutMessage() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class2.cs:line 38\n","start_date":1561543136000,"finish_date":1561543136000,"fail_reason":"Failed without any message. Please see logs on result page."},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":2,"start_date":1561543136000,"finish_date":1561543136000,"fail_reason":""},{"final_result_id":1,"start_date":1561543136000,"finish_date":1561543137000,"fail_reason":"Test exceeded Timeout value of 1000ms"},{"final_result_id":1,"log":" at Example.Tests.Class1.Test4() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class1.cs:line 59\n at Example.Tests.Class1.Test4() in C:\\Users\\v.kostyukevich\\Downloads\\example-net-nunit-master\\src\\Example\\Tests\\Class1.cs:line 59\n","start_date":1561543137000,"finish_date":1561543152000,"fail_reason":"Assertion:\r\n Expected: True\n But was: False\n"},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Here is OneTimeSetup exception."},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Here is OneTimeSetup exception."},{"final_result_id":3,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: Ignore reason for suite"},{"final_result_id":3,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: Ignore reason for suite"},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Assembly SetUpFixture exception."},{"final_result_id":1,"start_date":-62135769600000,"finish_date":-62135769600000,"fail_reason":"OneTimeSetUp: System.Exception : Assembly SetUpFixture exception."}]
1+
[{"final_result_id":2,"start_date":1584515817966,"finish_date":1584515817998,"fail_reason":""}]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"start_time":1561543135000,"execution_environment":"KOSTYUKEVICHV","finish_time":1561543152000,"author":"ITRANSITION\\v.kostyukevich"}
1+
{"start_time":1584515817966,"execution_environment":"user","finish_time":1584515818000,"author":"domain\\user"}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"Test Feature with all results: All passed","body":"Given passed step\r\nThen passed step"},{"name":"Test Feature with all results: step failed","body":"Given passed step\r\nThen failed step"},{"name":"Test Feature with all results: Step skipped","body":"Given passed step\r\nThen skipped step"}]
1+
[{"internalId":"SUITENAME.Gherkin.Features.Core.CORE.Administration.AdministrationMenu.ApplicationSettings.CORETC_1540Feature.CORETC_1540_Administration","name":"SUITENAME.Gherkin.Features.Core.CORE.Administration.AdministrationMenu.ApplicationSettings.CORETC_1540Feature.CORETC_1540_Administration"}]

0 commit comments

Comments
 (0)