Coder Social home page Coder Social logo

android-testing-templates's Introduction

Android Testing Templates

Android Testing Blueprint (in Java and Kotlin) - A collection of Google's Android testing tools and frameworks, all integrated in a single application project.

Android Testing Support Library

The testing templates use the ATSL. Visit the Android Testing Support Library site for more information.

Other Testing Samples

Android Testing samples - A collection of samples demonstrating different frameworks and techniques for automated testing.

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-testing-templates/issues

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

android-testing-templates's People

Contributors

josealcerreca avatar mauricegavin avatar slinzner avatar tiembo avatar yongce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-testing-templates's Issues

JUnit3 tests are not working

Hello,
I want to use the com.android.test plugin with JUnit3 instrumentation tests. Unfortunately this does not work because the ActivityInstrumentationTestCase2 class cannot be found by dalvik when the tests are started. Am I doing something wrong?

I forked the android-testing-templates here and pushed the changes for JUnit3.

Logcat reports:

Unable to resolve superclass of Lcom/example/android/testing/blueprint/test/AndroidTestOnlyModuleTest; 

This results in following output when running am instrument:

Time: 0
There was 1 failure:
1) com.example.android.testing.blueprint.test.AndroidTestOnlyModuleTest
java.lang.ClassNotFoundException: com.example.android.testing.blueprint.test.AndroidTestOnlyModuleTest
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:204)
    at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:94)
    at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:115)
    at android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(    TestRequestBuilder.java:712)
    at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:661)
    at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:329)
    at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:226)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: java.lang.NoClassDefFoundError: com/example/android/testing/blueprint/test/    AndroidTestOnlyModuleTest
    ... 9 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.testing.blueprint.test.AndroidTestOnlyModuleTest" on path: DexPathList[[zip file "/data/app/com.example.android.testing.blueprint.test-2.apk", zip file "/data/app/com.example.android.testing.blueprint.flavor1-2.apk"], nativeLibraryDirectories=[/data/app-lib/com.example.android.testing.blueprint.test-2, /data/app-lib/com.example.android.testing.blueprint.flavor1-2, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    ... 9 more

FAILURES!!!
Tests run: 0,  Failures: 1

Separate Android Test module cannot be run

Hi,

Thank you for your work but I'm having an error trying to run tests inside a separate module.

Running tests inside module-flavor1-androidTest-only module only produces Empty test suite error by both Android Studio and gradle command ./gradlew module-flavor1-androidTest-only:connectedAndroidTest

Another note, if I run a normal instrument test (which is located inside app module) first then the above tests can run without problem. My suspect is that the gradle command above doesn't install the app apk before execute the tests.

Can you guys check it out.

Thanks.

How do you add an Espresso test to the test-only module?

I tried to add an Espresso test to module-flavor1-androidTest-only, but I haven't gotten very far.

I copied EspressoTest into module-flavor1-androidTest-only and added the dependencies that it seemed to need.

My changes: master...bsstokes:add-espresso-test-to-test-only-module

When I run this new test, I'm getting:

java.lang.NullPointerException: Attempt to invoke interface method 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:410)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.android.testing.blueprint.HelloTestingBlueprintActivity.onCreate(HelloTestingBlueprintActivity.kt:44)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:532)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)


java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.testing.blueprint.flavor1/com.example.android.testing.blueprint.HelloTestingBlueprintActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:410)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.android.testing.blueprint.HelloTestingBlueprintActivity.onCreate(HelloTestingBlueprintActivity.kt:44)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:532)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
... 9 more

Test running failed: Instrumentation run failed due to 'Process crashed.'

Does anybody have any ideas?

It'd be awesome if somebody could add an Espresso test to module-flavor1-androidTest-only as an example.

Template should include the Play Services dependency

I'm mentioning this because adding Play Services dependency to the app module causes an error.

dependencies {
    // App's dependencies, including test
    compile('com.google.android.gms:play-services-base:7.5.0')
...

Reported error:

:module-flavor1-androidTest-only:processDebugManifest
/somewhere/android-testing-templates/AndroidTestingBlueprint/module-flavor1-androidTest-only/build/intermediates/manifests/full/debug/AndroidManifest.xml:29:28-65 : No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

If there is a better place to report this issue please direct me to it.

Template should include an usage of a dependency from a custom maven repository

Adding such dependency in the app module causes an "Failed to resolve" error.

repositories {
    maven { url "https://jitpack.io" }
    mavenCentral()
}

dependencies {
    // App's dependencies, including test
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.github.PhilJay:MPAndroidChart:v2.0.9'

...

If the same repositories are declared in the module-flavor1-androidTest-only module the dependencies resolve correctly.

Splits option breaks test module

I had an issue when trying to set up a testing module, based on the model provided in module-flavor1-androidTest-only. I eventually realized that it was due to the fact that I had ABI splits set up in my application, leading the connectedAndroidTest task to fail.

I was able to reproduce the issue in this project by adding the following snippet inside the android block of the app module's build.gradle file:

splits.abi {
    enable true
    reset()
    include 'armeabi', 'armeabi-v7a'
}

By running ./gradlew module-flavor1-androidTest-only:connectedDebugAndroidTest, I get the same exception as in my application.

> Expected configuration ':module-flavor1-androidTest-only:testTarget-metadata' to contain exactly one file, however, it contains no files.

By debugging Gradle, I found that the error occurs because TestApplicationData#getTestedApks handles modules with splits differently, since testedApkFiles.size() > 1 && splitSelectExe != null evaluates to true. The code then fails at TestApplicationData#loadMetadata.

I ended up disabling splits in my app, only when I'm running the instrumentation tests in this module. Any idea for a better workaround in the Gradle setup? Or is this just a bug in the Android Gradle Plugin which should be reported to their development team?

Test apk not getting shrinked (obfuscated)

If you try to minify (proguard) debug build by un-commenting :

 debug {
            // Run code coverage reports by default on debug builds.
            testCoverageEnabled = true

            // Uncomment this to run test against a minified version of the production APK
           
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFile 'proguard-test-rules.pro'
           
        }

in app's build.gradle, *-androidTest.apk doesnt get obfuscated and method count is not reduced.

Android Studio instructions outdated?

https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint#running-instrumentation-tests says:

In Android Studio

  • In the Build Variants window, make sure the Android Instrumentation Tests option is selected.
  • Open a Instrumentation test class like EspressoTest.java or UiAutomatorTest.java
  • Right click on the class and Run as Android Test.

For me (Android Studio 2.3.3 and 3 beta 6) there is no selection for this in "Build Variants".
On right clicking I also don't get "Run as ..." as an option, only "Run '...'".

What is the current equivalent for these instructions?

Error when build the project "No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_search_activated_mtrl_alpha')."

I am having this issue. Need Urgent Help

C:\Users\SmitShah\Downloads\jwplayer-sdk-android-demo-master\jwplayer-sdk-android-demo-master\CastCompanionLibrary-android\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.1\res\drawable\abc_textfield_search_material.xml
Error:(18, 87) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_search_activated_mtrl_alpha').
Error:(19, 89) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_search_activated_mtrl_alpha').
C:\Users\SmitShah\Downloads\jwplayer-sdk-android-demo-master\jwplayer-sdk-android-demo-master\CastCompanionLibrary-android\build\intermediates\exploded-aar\com.google.android.gms\play-services-base\8.3.0\res\drawable\common_google_signin_btn_icon_dark.xml
Error:(5, 27) No resource found that matches the given name (at 'drawable' with value '@drawable/common_google_signin_btn_icon_dark_disabled').
Error:(8, 27) No resource found that matches the given name (at 'drawable' with value '@drawable/common_google_signin_btn_icon_dark_pressed').
Error:(11, 27) No resource found that matches the given name (at 'drawable' with value

Code coverage report is always 0%

My project has a similar setup like the testing blueprint with an extra module for our Android tests. The app module has multiple flavors and build types (although I think that doesn't matter). If I try to create a code coverage report, then the coverage is 0% everywhere.

The Gradle plugin is trying to find and run the Android tests in the app module, but there are no tests. They are in the separate module.

Let me know if you need more information.

(Repost from the bug tracker https://code.google.com/p/android/issues/detail?id=199555)

Play Services dependency in app module causes "module-flavor1-androidTest-only" grade sync fail

Issue:
After adding Play Services to app module, gradle sync fails with message:

(...)/AndroidTestingBlueprint/module-flavor1-androidTest-only/build/intermediates/manifests/full/debug/AndroidManifest.xml
Error:(40, 28) No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

Use case:
main app module uses Google Play Services dependency:

  • Compile dependency in build.grade (app module)
  • meta-data in AndroidManifest.xml with play services version (app module)

After adding dependency, grade sync fails.

You can find separated changes committed here: jskierbi@6bbd1ac

Is it possible to fix this?

module not found

On the first build, doesn't find this package:

Error:(24, 66) error: package com.example.android.testing.blueprint.androidlibrarymodule does not exist

Error when build the project "No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_search_activated_mtrl_alpha')."

No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_search_activated_mtrl_alpha').

android-testing-templates-master\AndroidTestingBlueprint\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\res\drawable\abc_textfield_search_material.xml

Error:Execution failed for task ':app:processFlavor1DebugResources'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'Android\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.