From 7d30e0a60f3456b776c6f2210db7831c7a934b41 Mon Sep 17 00:00:00 2001 From: Piotr Maszota <37781044+piotruela@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:33:07 +0200 Subject: [PATCH] fix: Modify test names inside PatrolJUnitRunner to remove spaces (#2361) * fix: Modify test names inside PatrolJUnitRunner to remove spaces * fix: Explain changes in the code * chore: Prepare version and changelog for release --------- Co-authored-by: piotruela --- packages/patrol/CHANGELOG.md | 4 ++++ .../pl/leancode/patrol/PatrolJUnitRunner.java | 24 ++++++++++++++++--- packages/patrol/pubspec.yaml | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/patrol/CHANGELOG.md b/packages/patrol/CHANGELOG.md index f22819462..852bbeced 100644 --- a/packages/patrol/CHANGELOG.md +++ b/packages/patrol/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.11.1 + +- Replace whitespace in test case name in `PatrolJUnitRunner.java`. (#2361) + ## 3.11.0 - Add code coverage collection support. (#2294) diff --git a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/PatrolJUnitRunner.java b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/PatrolJUnitRunner.java index a9ced7b5d..1e5b35648 100644 --- a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/PatrolJUnitRunner.java +++ b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/PatrolJUnitRunner.java @@ -35,6 +35,8 @@ public class PatrolJUnitRunner extends AndroidJUnitRunner { public PatrolAppServiceClient patrolAppServiceClient; private Map dartTestCaseSkipMap = new HashMap<>(); + private String spaceReplacement = "__"; + @Override protected boolean shouldWaitForActivitiesToComplete() { return false; @@ -115,8 +117,9 @@ public Object[] listDartTests() { List dartTestCases = ContractsExtensionsKt.listTestsFlat(dartTestGroup, ""); List dartTestCaseNamesList = new ArrayList<>(); for (DartGroupEntry dartTestCase : dartTestCases) { - dartTestCaseSkipMap.put(dartTestCase.getName(), dartTestCase.getSkip()); - dartTestCaseNamesList.add(dartTestCase.getName()); + final String testName = sanitizeTestCaseName(dartTestCase.getName()); + dartTestCaseSkipMap.put(testName, dartTestCase.getSkip()); + dartTestCaseNamesList.add(testName); } Object[] dartTestCaseNames = dartTestCaseNamesList.toArray(); Logger.INSTANCE.i(TAG + "Got Dart tests: " + Arrays.toString(dartTestCaseNames)); @@ -142,7 +145,7 @@ public RunDartTestResponse runDartTest(String name) { try { Logger.INSTANCE.i(TAG + "Requested execution"); - RunDartTestResponse response = patrolAppServiceClient.runDartTest(name); + RunDartTestResponse response = patrolAppServiceClient.runDartTest(originalTestCaseName(name)); if (response.getResult() == Contracts.RunDartTestResponseResult.failure) { throw new AssertionError("Dart test failed: " + name + "\n" + response.getDetails()); } @@ -152,4 +155,19 @@ public RunDartTestResponse runDartTest(String name) { throw new RuntimeException(e); } } + + /** + * We need to remove whitespaces from test case name in order to make in compatible with Orchestrator 1.5.0. + * New requirement can be observed (here). + * */ + private String sanitizeTestCaseName(String name) { + return name.replace(" ", spaceReplacement); + } + + /** + * When calling test on dart side, we need to bring back original test case name. + * */ + private String originalTestCaseName(String name) { + return name.replace(spaceReplacement, " "); + } } diff --git a/packages/patrol/pubspec.yaml b/packages/patrol/pubspec.yaml index 702be1d0c..edcffecf5 100644 --- a/packages/patrol/pubspec.yaml +++ b/packages/patrol/pubspec.yaml @@ -2,7 +2,7 @@ name: patrol description: > Powerful Flutter-native UI testing framework overcoming limitations of existing Flutter testing tools. Ready for action! -version: 3.11.0 +version: 3.11.1 homepage: https://patrol.leancode.co repository: https://github.com/leancodepl/patrol/tree/master/packages/patrol issue_tracker: https://github.com/leancodepl/patrol/issues