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

Introduce suite name and some bugs fixing #21

Merged
merged 1 commit into from
Jul 8, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public TestResult format(final ExportMeta meta, final JsonNode node) {
if (Objects.nonNull(result.getStart())) {
if (node.has(DURATION)) {
final Double durationText = node.get(DURATION).get(VALUE).asDouble();
result.setStop(result.getStart() + TimeUnit.SECONDS.toMillis(durationText.longValue()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix test run that take lesser than 1 second will show as 0 second in allure report.

long durationToMillis = (long) (durationText * 1000);
result.setStop(result.getStart() + durationToMillis);
}
if (result.getSteps().size() > 0) {
result.setStop(result.getSteps().get(result.getSteps().size() - 1).getStop());
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public class ExportCommand implements Runnable {

private static final String SUMMARY_REF = "summaryRef";

private static final String SUITE = "suite";

private static final String ID = "id";
private static final String TYPE = "_type";
private static final String NAME = "_name";
private static final String VALUE = "_value";
private static final String VALUES = "_values";
private static final String DISPLAY_NAME = "displayName";
private static final String IDENTIFIER = "identifier";
private static final String TARGET_NAME = "targetName";

private static final String TEST_REF = "testsRef";

Expand Down Expand Up @@ -108,19 +110,22 @@ private void runUnsafe() throws Exception {
testRefIds.put(action.get(ACTION_RESULT).get(TEST_REF).get(ID).get(VALUE).asText(), meta);
}
}

final Map<JsonNode, ExportMeta> testSummaries = new HashMap<>();
testRefIds.forEach((testRefId, meta) -> {
final JsonNode testRef = getReference(testRefId);
for (JsonNode summary : testRef.get(SUMMARIES).get(VALUES)) {
for (JsonNode testableSummary : summary.get(TESTABLE_SUMMARIES).get(VALUES)) {
final ExportMeta testMeta = getTestMeta(meta, testableSummary);
for (JsonNode test : testableSummary.get(TESTS).get(VALUES)) {
getTestSummaries(test).forEach(testSummary -> {
testSummaries.put(testSummary, testRefIds.get(testRefId));
testSummaries.put(testSummary, testMeta);
});
}
}
}
});

System.out.println(String.format("Export information about %s test summaries...", testSummaries.size()));
final Map<String, String> attachmentsRefs = new HashMap<>();
testSummaries.forEach((testSummary, meta) -> {
Expand All @@ -139,6 +144,17 @@ private void runUnsafe() throws Exception {
}
}

private ExportMeta getTestMeta(ExportMeta meta, JsonNode testableSummary) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure suite name is captured and exported as part of JSON so that allure report when generate, the test will be categorised by suite

final ExportMeta exportMeta = new ExportMeta();
exportMeta.setStart(meta.getStart());
meta.getLabels().forEach((key, value) -> {
exportMeta.label(key, value);
});

exportMeta.label(SUITE, testableSummary.get(TARGET_NAME).get(VALUE).asText());
return exportMeta;
}

private void exportTestSummary(final ExportMeta meta, final JsonNode testSummary) {
Path testSummaryPath = null;
Object formattedResult = null;
Expand Down Expand Up @@ -190,10 +206,12 @@ private List<JsonNode> getTestSummaries(final JsonNode test) {
if (test.has(SUMMARY_REF)) {
final String ref = test.get(SUMMARY_REF).get(ID).get(VALUE).asText();
summaries.add(getReference(ref));
} else {
if (test.has(TYPE) && test.get(TYPE).get(NAME).textValue().equals("ActionTestMetadata")) {
summaries.add(test);
}
}
if (test.has(TYPE) && test.get(TYPE).get(NAME).textValue().equals("ActionTestMetadata")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the introduction of unit test support has resulted in duplicate tests being exported in JSON. When allure report is generated, the number of tests shown are double.

summaries.add(test);
}

if (test.has(SUBTESTS)) {
for (final JsonNode subTest : test.get(SUBTESTS).get(VALUES)) {
summaries.addAll(getTestSummaries(subTest));
Expand Down