Skip to content

Commit

Permalink
fix: Modify test names inside PatrolJUnitRunner to remove spaces (#2361)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
piotruela and piotruela authored Oct 8, 2024
1 parent c271ba4 commit 7d30e0a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/patrol/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class PatrolJUnitRunner extends AndroidJUnitRunner {
public PatrolAppServiceClient patrolAppServiceClient;
private Map<String, Boolean> dartTestCaseSkipMap = new HashMap<>();

private String spaceReplacement = "__";

@Override
protected boolean shouldWaitForActivitiesToComplete() {
return false;
Expand Down Expand Up @@ -115,8 +117,9 @@ public Object[] listDartTests() {
List<DartGroupEntry> dartTestCases = ContractsExtensionsKt.listTestsFlat(dartTestGroup, "");
List<String> 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));
Expand All @@ -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());
}
Expand All @@ -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 (<a href="https://github.com/android/android-test/commit/8383d784e51dd67972f79f7738e19e7e99706d23">here</a>).
* */
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, " ");
}
}
2 changes: 1 addition & 1 deletion packages/patrol/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d30e0a

Please sign in to comment.