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

[trainer] Return Test Plan Configuration in JUnit output #20016

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion trainer/lib/assets/junit.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<testsuites tests="<%= number_of_tests %>" failures="<%= number_of_failures %>">
<% @results.each do |testsuite| %>
<testsuite name=<%= (testsuite[:target_name].nil? ? testsuite[:test_name] : testsuite[:target_name]).encode(:xml => :attr) %> tests="<%= testsuite[:number_of_tests_excluding_retries] %>" failures="<%= testsuite[:number_of_failures_excluding_retries] %>" <% if testsuite[:number_of_skipped] %>skipped="<%= testsuite[:number_of_skipped] %>" <% end %>time="<%= testsuite[:duration] %>">
<% unless testsuite[:configuration_name].nil? %>
<properties>
<property name="Configuration" value="<%= testsuite[:configuration_name] %>"/>
</properties>
<% end %>
<% testsuite[:tests].each do |test| %>
<testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %> time="<%= test[:duration] %>">
<% (test[:failures] || []).each do |failure| %>
Expand All @@ -15,7 +20,7 @@
<% end %>
<% if test[:skipped] %>
<skipped/>
<% end%>
<% end %>
</testcase>
<% end %>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion trainer/lib/trainer/junit_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def generate

xml = xml.gsub('system_', 'system-').delete("\e") # Jenkins can not parse 'ESC' symbol

# We have to manuall clear empty lines
# We have to manually clear empty lines
# They may contain white spaces
clean_xml = []
xml.each_line do |row|
Expand Down
13 changes: 13 additions & 0 deletions trainer/lib/trainer/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def summaries_to_data(summaries, failures, output_remove_retry_attempts: false)
all_summaries = summaries.map(&:summaries).flatten
testable_summaries = all_summaries.map(&:testable_summaries).flatten

summaries_to_names = test_summaries_to_configuration_names(all_summaries)

# Maps ActionTestableSummary to rows for junit generator
rows = testable_summaries.map do |testable_summary|
all_tests = testable_summary.all_tests.flatten
Expand Down Expand Up @@ -317,6 +319,7 @@ def summaries_to_data(summaries, failures, output_remove_retry_attempts: false)
project_path: testable_summary.project_relative_path,
target_name: testable_summary.target_name,
test_name: testable_summary.name,
configuration_name: summaries_to_names[testable_summary],
duration: all_tests.map(&:duration).inject(:+),
tests: test_rows
}
Expand All @@ -337,6 +340,16 @@ def summaries_to_data(summaries, failures, output_remove_retry_attempts: false)
self.data = rows
end

def test_summaries_to_configuration_names(test_summaries)
summary_to_name = {}
test_summaries.each do |summary|
summary.testable_summaries.each do |testable_summary|
summary_to_name[testable_summary] = summary.name
end
end
summary_to_name
end

# Convert the Hashes and Arrays in something more useful
def parse_content(xcpretty_naming)
self.data = self.raw_json["TestableSummaries"].collect do |testable_summary|
Expand Down
31 changes: 31 additions & 0 deletions trainer/spec/fixtures/XCResult.junit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="7" failures="2">
<testsuite name="TestUITests" tests="1" failures="0" skipped="0" time="16.05245804786682">
<properties>
<property name="Configuration" value="Test Scheme Action"/>
</properties>
<testcase classname="TestUITests" name="testExample()" time="16.05245804786682">
</testcase>
</testsuite>
<testsuite name="TestThisDude" tests="6" failures="2" skipped="0" time="0.5279300212860107">
<properties>
<property name="Configuration" value="Test Scheme Action"/>
</properties>
<testcase classname="TestTests" name="testExample()" time="0.0005381107330322266">
</testcase>
<testcase classname="TestTests" name="testFailureJosh1()" time="0.006072044372558594">
<failure message="XCTAssertTrue failed (/Users/josh/Projects/fastlane/test-ios/TestTests/TestTests.swift#CharacterRangeLen=0&amp;EndingLineNumber=36&amp;StartingLineNumber=36)">
</failure>
</testcase>
<testcase classname="TestTests" name="testPerformanceExample()" time="0.2661939859390259">
</testcase>
<testcase classname="TestThisDude" name="testExample()" time="0.0004099607467651367">
</testcase>
<testcase classname="TestThisDude" name="testFailureJosh2()" time="0.001544952392578125">
<failure message="XCTAssertTrue failed (/Users/josh/Projects/fastlane/test-ios/TestThisDude/TestThisDude.swift#CharacterRangeLen=0&amp;EndingLineNumber=35&amp;StartingLineNumber=35)">
</failure>
</testcase>
<testcase classname="TestThisDude" name="testPerformanceExample()" time="0.2531709671020508">
</testcase>
</testsuite>
</testsuites>
6 changes: 6 additions & 0 deletions trainer/spec/junit_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@
junit = File.read("./trainer/spec/fixtures/Valid2-x.junit")
expect(tp.to_junit).to eq(junit)
end

it "works with an xcresult", requires_xcode: true do
tp = Trainer::TestParser.new("./trainer/spec/fixtures/Test.test_result.xcresult")
junit = File.read("./trainer/spec/fixtures/XCResult.junit")
expect(tp.to_junit).to eq(junit)
end
end
end
2 changes: 2 additions & 0 deletions trainer/spec/test_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
project_path: "Test.xcodeproj",
target_name: "TestUITests",
test_name: "TestUITests",
configuration_name: "Test Scheme Action",
duration: 16.05245804786682,
tests: [
{
Expand All @@ -118,6 +119,7 @@
project_path: "Test.xcodeproj",
target_name: "TestThisDude",
test_name: "TestThisDude",
configuration_name: "Test Scheme Action",
duration: 0.5279300212860107,
tests: [
{
Expand Down