[android] - add config file for excluding generated tests, refactor generation script output
This commit is contained in:
@@ -49,8 +49,9 @@ public abstract class BaseActivityTest {
|
||||
throw new RuntimeException("Could not start test for " + getActivityClass().getSimpleName() + ".\n"
|
||||
+ "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n"
|
||||
+ "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"
|
||||
+ "You can resolve this issue be implementing the requirements above or\n add "
|
||||
+ getActivityClass().getSimpleName() + " to the excludeActivities array in `generate-test-code.js`.\n");
|
||||
+ "You can resolve this issue by adding the requirements above or\n add "
|
||||
+ getActivityClass().getSimpleName() + " to the platform/android/scripts/exclude-activity-gen.json to blacklist"
|
||||
+ " the Activity from being generated.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +68,7 @@ public abstract class BaseActivityTest {
|
||||
protected abstract Class getActivityClass();
|
||||
|
||||
protected void checkViewIsDisplayed(int id) {
|
||||
onView(withId(id))
|
||||
.check(matches(isDisplayed()));
|
||||
onView(withId(id)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
protected void waitLoop() {
|
||||
|
||||
@@ -13,10 +13,8 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private IdlingResource.ResourceCallback resourceCallback;
|
||||
private Activity activity;
|
||||
|
||||
public OnMapReadyIdlingResource(Activity activity) {
|
||||
this.activity = activity;
|
||||
try {
|
||||
Field field = activity.getClass().getDeclaredField("mapView");
|
||||
field.setAccessible(true);
|
||||
@@ -24,7 +22,6 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
} catch (Exception err) {
|
||||
throw new RuntimeException(err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,4 +50,4 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
platform/android/scripts/exclude-activity-gen.json
Normal file
31
platform/android/scripts/exclude-activity-gen.json
Normal file
@@ -0,0 +1,31 @@
|
||||
[
|
||||
"BaseLocationActivity",
|
||||
"MapSnapshotterMarkerActivity",
|
||||
"MapSnapshotterReuseActivity",
|
||||
"LatLngBoundsActivity",
|
||||
"BottomSheetActivity",
|
||||
"MapSnapshotterActivity",
|
||||
"MockLocationEngine",
|
||||
"DeleteRegionActivity",
|
||||
"RealTimeGeoJsonActivity",
|
||||
"UpdateMetadataActivity",
|
||||
"CarDrivingActivity",
|
||||
"MyLocationTrackingModeActivity",
|
||||
"MyLocationToggleActivity",
|
||||
"MyLocationTintActivity",
|
||||
"MyLocationDrawableActivity",
|
||||
"DoubleMapActivity",
|
||||
"LocationPickerActivity",
|
||||
"GeoJsonClusteringActivity",
|
||||
"RuntimeStyleTestActivity",
|
||||
"AnimatedMarkerActivity",
|
||||
"ViewPagerActivity",
|
||||
"MapFragmentActivity",
|
||||
"SupportMapFragmentActivity",
|
||||
"SnapshotActivity",
|
||||
"NavigationDrawerActivity",
|
||||
"QueryRenderedFeaturesBoxHighlightActivity",
|
||||
"MultiMapActivity",
|
||||
"MapInDialogActivity",
|
||||
"SimpleMapActivity"
|
||||
]
|
||||
@@ -13,8 +13,7 @@ global.camelize = function (str) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const excludeActivities = ["BaseLocationActivity","MapSnapshotterMarkerActivity","MapSnapshotterReuseActivity","LatLngBoundsActivity","BottomSheetActivity","MapSnapshotterActivity","","MockLocationEngine","DeleteRegionActivity","RealTimeGeoJsonActivity","UpdateMetadataActivity","CarDrivingActivity","MyLocationTrackingModeActivity","MyLocationToggleActivity","MyLocationTintActivity","MyLocationDrawableActivity","DoubleMapActivity", "LocationPickerActivity","GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity", "QueryRenderedFeaturesBoxHighlightActivity", "MultiMapActivity", "MapInDialogActivity", "SimpleMapActivity"];
|
||||
const excludeClasses = JSON.parse(fs.readFileSync('platform/android/scripts/exclude-activity-gen.json', 'utf8'));
|
||||
const appBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity';
|
||||
const testBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/gen';
|
||||
const subPackages = fs.readdirSync(appBasePath);
|
||||
@@ -24,7 +23,9 @@ if (!fs.existsSync(testBasePath)){
|
||||
fs.mkdirSync(testBasePath);
|
||||
}
|
||||
|
||||
console.log("Generating test activities:");
|
||||
console.log("\nGenerating test activities:\n");
|
||||
var generatedClasses = [];
|
||||
var excludedClasses = [];
|
||||
for(const subPackage of subPackages) {
|
||||
if(!(subPackage.slice(-5) == '.java')) {
|
||||
const activities = fs.readdirSync(appBasePath+'/'+subPackage);
|
||||
@@ -45,18 +46,22 @@ for(const subPackage of subPackages) {
|
||||
try {
|
||||
fs.accessSync(filePath, fs.F_OK);
|
||||
fs.unlinkSync(filePath);
|
||||
console.log("Removed file: "+filePath);
|
||||
} catch (e) {
|
||||
console.log("No file found: "+filePath);
|
||||
}
|
||||
|
||||
// only generate test file if not part of exclude list
|
||||
if (!(excludeActivities.indexOf(activityName) > -1)) {
|
||||
console.log("Created file: "+filePath);
|
||||
// only generate test file if not part of exclude list + if contains Activity in name
|
||||
if ((!(excludeClasses.indexOf(activityName) > -1)) && activityName.includes("Activity")) {
|
||||
fs.writeFileSync(filePath, ejsConversionTask([activityName, subPackage]));
|
||||
generatedClasses.push(activityName);
|
||||
}else{
|
||||
console.log("Excluding file: "+filePath);
|
||||
excludedClasses.push(activityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(const generatedClass of generatedClasses){
|
||||
console.log(generatedClass+"Test");
|
||||
}
|
||||
|
||||
console.log("\nFinished generating " + generatedClasses.length + " activity sanity tests, excluded " + excludeClasses.length + " classes.\n");
|
||||
Reference in New Issue
Block a user