diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2017-11-02 09:51:07 -0700 |
---|---|---|
committer | tobrun <tobrun.van.nuland@gmail.com> | 2017-11-07 13:26:03 +0100 |
commit | 2ef8151ab2911341d7344469bd2d693df466101b (patch) | |
tree | 05852fcaa8749590c1ca08d646d6b04ef587864d | |
parent | d29ebe3d3fb8dad6187974edf8273208a4a0680c (diff) | |
download | qtlocation-mapboxgl-upstream/tvn-activity-gen.tar.gz |
[android] - add config file for excluding generated tests, refactor generation script outputupstream/tvn-activity-gen
4 files changed, 50 insertions, 17 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java index c029bc09c4..61bff1f113 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java @@ -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() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java index 1c4981ca5e..0e2e4587ee 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java @@ -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(); } } -} +}
\ No newline at end of file diff --git a/platform/android/scripts/exclude-activity-gen.json b/platform/android/scripts/exclude-activity-gen.json new file mode 100644 index 0000000000..f05001c6ae --- /dev/null +++ b/platform/android/scripts/exclude-activity-gen.json @@ -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" +]
\ No newline at end of file diff --git a/platform/android/scripts/generate-test-code.js b/platform/android/scripts/generate-test-code.js index 5be9cbbaf0..e27de7e40b 100644 --- a/platform/android/scripts/generate-test-code.js +++ b/platform/android/scripts/generate-test-code.js @@ -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");
\ No newline at end of file |