I'm new to testing on Android. I see a lot of articles and tutorial about unit testing and with end-to-end testing (with espresso). It's ok. But what about integration testing ?
For the exemple, I use Firebase Database for my app. Is it possible to do this kind of test in the instrumentation test :
#Test
public void tryFirebaseTest() throws FieldRequiredException, InvalidPhoneException, InvalidEmailException, InterruptedException {
UserManager userManager = new UserManager(new FIRUserStorage(FirebaseDatabase.getInstance().getReference()));
userManager.createUser("test#test.com", "test", "+4778787", "", new CreateUserCallback() {
#Override
public void userCreated(User user) {
assertNotNull(user);
}
#Override
public void userExistError() {
fail();
}
#Override
public void userDatabaseError(String errorMessage) {
fail();
}
});
}
In this case, the test don't get in the callback.
For integration testing a Firebase app, you currently have two options:
Run local-firebase server, as discussed in this article, and write integration tests in jUnit/TestNG or whatever automation framework you like.
Write Espresso tests to test the complete integration
There are a few tools to help with the mocking like fingular, but you'll have to play with it a bit to see what kind of mileage you'll get out per your project and to what extent you integration test.
Related
I started to learning about Android lately.
Now i'm trying to test some random Application with Robotium with Black-box testing method with no sources code or ID.
The app i tried to test:
https://play.google.com/store/apps/details?id=com.zing.zalo&hl=en
.
Just some simple function like: Open the app, login, log out.
I implented External Jar "robotium" in the JUnit test project, build path is checked with robotium and everything else.
I struggled with Pkg name, and activity name, then i saw some adb platform-toll "adb shell dumpsys activity" in the site below to get the name from my phone.
ADB - Android - Getting the name of the current activity
And many hours i read and searched from many sites this is the code i came up with:
public class LoginZalo extends ActivityInstrumentationTestCase2 {
public static Class LauncherActivityFullClass;
public Solo solo;
String pkg = "com.zing.zalo";
private static String launcher_activity_full_class = "/.ui.ZaloLauncherActivity";//login interface
static{
try {
LauncherActivityFullClass = Class.forName(launcher_activity_full_class);
} catch (Exception e) {
throw new RuntimeException();
}
}
public LoginZalo()
{
super(LauncherActivityFullClass);
}
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(),getActivity());
}
public void ZaloLogin()
{
solo.clickOnButton("LOGIN");
//also tried solo.clickOnButton(0); or solo.clickOnButton(1); or even clickOnText("LOGIN");
}
#Override
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
solo.finishOpenedActivities();
}
}
AndroidManifest add target package.
<instrumentation
android:name="android.test.InstrumenttationTestRunner"
android:targetPackage="com.zing.zalo" />
But i only got a red error "Test run failed: No test results"in the console. I saw there is an comment on Robotium GitHub said Robotium can't do Black-box testing. I tried so many things from many site for many hours but getting nowhere. So i wonder, can Robotium Eclipse can do Black-box testing ? Maybe i did something wrong, because on Github site, they said Robotium can do black-box testing. Or i have to do it with Android Studio + Robotium Recorder ? Or maybe i should try something else like Appium ?
I'm using Robolectric 4.2 to write unit test cases for one of my Android applications. The test case is very simple like below:
#Before
public void setUp() {
landingActivity = Robolectric.setupActivity(LandingActivity.class);
}
#Test
public void shouldNotBeNull() {
assertNotNull(landingActivity);
}
But its taking forever to get completed. Can someone help me out what is happening and is there anything I'm missing.
Trying to integrate the AppsFlyer SDK for Android, I've followed all the steps indicated in the AppsFlyer guide. Initially, the dependency that was stated is:
implementation 'com.appsflyer:af-android-sdk:4+#aar'
But for some reason, it wasn't pointing to the latest version on it's own, making the init() version not visible. And so I instead went ahead and adjusted it to version 4.8.15 (currently the latest version), which worked as expected in the guide.
After adding the required permissions (with the optional permission) and the BroadcastReceiver (I don't have any other receivers for the referrer so I only used the SingleInstallBroadcastReceiver), I implemented the initialization on the app's Application class like so:
public class MyApp extends Application {
private static final String AF_DEV_KEY = "DEV_KEY_FROM_CONSOLE_HERE";
#Override
public void onCreate() {
super.onCreate()
initAppsFlyer();
}
public void initAppsFlyer() {
final AppsFlyerConversionListener listener = new AppsFlyerConversionListener() {
#Override
public void onInstallConversionDataLoaded(Map<String, String> conversionData) {
}
#Override
public void onInstallConversionFailure(String errorMessage) {
}
#Override
public void onAppOpenAttribution(Map<String, String> attributionData) {
}
#Override
public void onAttributionFailure(String errorMessage) {
}
};
AppsFlyerLib.getInstance().init(AF_DEV_KEY, listener, this);
AppsFlyerLib.getInstance().startTracking(this);
}
}
The manifest is pointing to the MyApp application class for sure. So that's it. The initial setup is complete. Time for the SDK Integration test as per the guide.
So I installed the app directly from Android Studio to my device, downloaded SDK Integration test app, whitelisted the device, and selected the name of the app as mentioned in the test guide. Every step followed accordingly.
Clicked on SDK Integration Testing...
Checking configuration...
Testing your app..
*app opens*
*closes*
*opens again*
Testing your app..
Checking configuration...
..
X Oops..
This app can not be monitored. Please make sure that:
You are using a supported AppsFlyer SDK version.
AppsFyler's BroadcastReceiver is configured.
startTracking() is placed in the MainActivity
It's the latest version. So it should work.
Copy pasted the receiver. Tried removing it and then re-run the test, it showed the missing receiver error. Pasted it back in.
I'm calling startTracking() in the actual application class. But what the heck. I gave it a try, called it in the MainActivity.onCreate() same result.
I have no idea what is causing the failure in the test. Not much to go on from as well since there's no details on how to debug it further. However, I checked the Dashboard, and there it is. Non-Organic install data counted.
Now I'm confused. Is there an issue with the integration or with the SDK integration test app?
I'm writing UI Automation tests for an Android app using Espresso. The test will search for a barcode number and find the associated item, but this feature is only available to US users. The users market is identified by the device language (en_US, en_UK).
How can I write this test so that it won't fail every time I run the automated tests for the UK?
I accomplished this with XCTest for the iOS app by creating a method that checks the devices current language.
class MarketChecker: XCTestCase {
func isUSLocale() -> Bool {
return Locale.current.identifier == "en_US"
}
func isGBLocale() -> Bool {
return Locale.current.identifier == "en_GB"
}
}
The method is then called at the start of the test:
if isUSLocale() {
<US specific test>
}
This allows me to run the same test suite without having failures caused by our apps regional differences.
Unfortunately (for me) Espresso does not like if statements so I'm not sure how to implement this for the Android app. Any insights would be hugely appreciated!
Managed to figure it out. This is useful if your app is in multiple markets controlled by the device language.
public static String deviceLocale() {
return Locale.getDefault().getCountry();
}
public static boolean isGBLocale() {
return deviceLocale().equals("GB");
}
public static boolean isAULocale() {
return deviceLocale().equals("AU");
}
public static boolean isUSLocale() {
return deviceLocale().equals("US");
}
This can be used to validate market specific differences or skip tests that would otherwise fail in that market.
if (isUSLocale()) {
// US test
}
I want to test that when I receive push, Notification will be showing up. And it might be as well to check its properties (like title, set intent and so on.)
How can I do so?
#Before
public void setupTest() {
mData.putString(PushNotificator.KEY_PUSH_TYPE, PushType.PROJECT_OFFER.toString());
mData.putString(PushNotificator.KEY_PUSH_OBJECT, pushObjectJsonString);
mContext = InstrumentationRegistry.getContext();
}
#Test
public void projectOfferCreatedFromBundle() {
mPushNotificator = new PushNotificator(mContext);
mPushNotificator.processPush(mData);
onView(withText("111")).check(matches(withText("111"))); //how to find notification?
}
Espresso UI test framework doesn't see more than actual View. I doubt seriously that you can check any notification with Espresso.
For this purpose use another Googles testing framework uiautomator, which is described as:
UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
Here you would find how to use it with Espresso: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
More information:
Documentation(I):
https://google.github.io/android-testing-support-library/docs/uiautomator/index.html
Documentation(II):
http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html
Visit also: Android Testing: UIAutomator vs Espresso