different testcase example for androidTest and test folder in android studio - android

Android studio is creating 2 folder androidTest and test. can anyone give example of testcases for both folders.

The test/ folder will contain unit testing code that runs on your system's JVM. This is the same as plain java unit testing, so any classes that don't touch the Android framework would work great here.
The androidTest/ folder will contain instrumentation tests instead - these require a device or emulator to run. Things you'd test with it are Activities, Services, Providers, etc.
For examples on both, you can refer to the documentation:
https://github.com/googlesamples/android-testing
https://google.github.io/android-testing-support-library/samples/index.html

Related

Android - Is it possible to access instrumened test and unit test classes in androidTest and test folders programmatically?

Is there a way to access the test classes in AndroidTest and test folders from my code? I can access tests placed in the same folder than my activity but not from these test folders.
Here is a picture to explain what I mean:
I am using Android Studio and Kotlin.
Thanks in advance for any help
is there a way to access the test classes in androidTest and test folders from code?
If by "from code" you mean "from classes in the main/ source set", then no, that is not possible.
I want to do that to run test after an admin clicked a button.
Android tests (androidTest and test) are run by the Android SDK tools. Unit tests (test) are run on a development machine, not the device. Instrumented tests (androidTest) require special permissions to run and cannot be executed directly by an ordinary Android app.

Running functional tests on firebase

I will want to run a functional tests on firebase on various devices. Does firebase support functional testing in android?
Their testlab has three types of tests:
Robo test
Instrumentation test
Gameloop
Robo test is ruled out as it is just a stress test and a load test like a money runner
When it comes to instrumentation test, first thing I want to be clear on whether it is a functional test written in expresso, UIautomator and ranorex?
If yes, I see that I have to upload two .apk's in there, one is AppApk and TestApk. I would like to know if AppApk is the application under test and TestApk is the apk that is created to test the application?
If yes, I found uiautomator tests are bundled inside the src folder and is a java file. I also found that, there is a python wrapper for uiautomator that can be coded to write tests for android.
Now there is kivy.org to bundle python file into an .apk since android studio does not support python.
Now, How do i run Android uiautomator tests in python? Is there a way, to run python scripts inside the android studio?
And How to run functional tests in firebase? Do they support?

Using Appium and Espresso together a bad idea?

I'm a fanboy of Test-pyramid application in software development and want the same to be applied in Mobile software development as well.
For this, I'm desiring to leverage both Appium (for functional tests) and Espresso (for Integration Tests), and have the following questions:
The structure of my tests in Android Studio with Gradle has only 2 folders: app/src/test and app/src/androidTest.
The former test is meant for writing Unit tests with JUnit. The later for functional tests; and I'm using espresso tests for integration-testing making use of the latter directory.
I know I can create a separate project for Appium and write functional tests. But prefer to have those as part of the project in separate test source directory, so that it can be run at different intervals in my CI pipeline. How do I go about doing this? Is it possible to create another source test directory like app/src/functionalTest? Pointers to sample projects in github or resources is well appreciated.

Android Studio creates a test folder, why?

Android studio creates a test folder called androidTest with an ApplicationTest.java file by default upon creating a new project. It's obviously used for testing, but what kind of testing? In what circumstances should I use the test folder when developing an Android app?
but what kind of testing
The instrumentation testing that centers around the technologies in the Testing Support Library (e.g., Espresso, UI Automator).
You can do Android Instumentation Tests, or regular Junit4 testing. I recommend you do some kind of testing, if only to prevent regression of bugs. I favor test driven development (TDD), cf http://blog.pivotal.io/labs/labs/tdd-android-pov

JUnit and Android?

Is anyone using Junit and Android? Or is that just a worthy hope? Is there a tutorial anywhere?
Android has great support for JUnit 3
From Testing Fundamentals on Android Developers:
The Android testing framework, an integral part of the development environment, provides an architecture and powerful tools that help you test every aspect of your application at every level from unit to framework.
The testing framework has these key features:
Android test suites are based on JUnit. You can use plain JUnit to test a class that doesn't call the Android API, or Android's JUnit extensions to test Android components. If you're new to Android testing, you can start with general-purpose test case classes such as AndroidTestCase and then go on to use more sophisticated classes.
The Android JUnit extensions provide component-specific test case classes. These classes provide helper methods for creating mock objects and methods that help you control the lifecycle of a component.
Test suites are contained in test packages that are similar to main application packages, so you don't need to learn a new set of tools or techniques for designing and building tests.
The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDES. These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file, and directory structure for the test package.
The SDK also provides monkeyrunner, an API testing devices with Python programs, and UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.
This document describes the fundamentals of the Android testing framework, including the structure of tests, the APIs that you use to develop tests, and the tools that you use to run tests and view results. The document assumes you have a basic knowledge of Android application programming and JUnit testing methodology.
I have been using Roboelectric which is awesome because it does not launch the simulator making the run time for the tests very very quick. A sample project is provided as an example and can be found here at github
You can also use Robotium to drive the UI from within JUnit for more functional style testing.
"Note that the Android testing API supports JUnit 3 code style, but not JUnit 4." (Source)
If you want to use JUnit4 or have existing JUnit4 tests you can use JUnit4Android.

Categories

Resources