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

fix: Modify test names inside PatrolJUnitRunner to remove spaces #2361

Merged
merged 3 commits into from
Oct 8, 2024
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
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
Loading