We are trying to use the Robolectric testing framework in Android Studio in order to test the Facebook API. The Facebook Login button works so the Facebook API is working. However, the following test fails:
package com.airportapp.test.Models;
import android.app.Activity;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.Robolectric;
import com.airportapp.test.MyRobolectricTestRunner;
import com.airportapp.LoginActivity;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
#RunWith(MyRobolectricTestRunner.class)
public class LoginActivityTest {
#Before
public void setup() {
//do whatever is necessary before every test
}
#Test
public void testActivityFound() {
Activity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
Assert.assertNotNull(activity);
}
}
And the error is that Android Studio could not find the android.support file when we run the tests. You can see the error here:
The other error that shows up is:
android.view.InflateException: XML file app/src/main/res/layout/activity_login.xml line #-1 (sorry, not yet implemented): Error inflating class com.facebook.widget.LoginButton
So Android Studio is not happy with the facebook login button as well :( But it works... We think that we need to import something, but we don't know where to put it.
The InflateException is because Robolectric cannot find the resources from the Facebook SDK. To solve this, the project.properties file has to be updated to point to the Facebook SDK project. Do this by adding the following line to it:
android.library.reference.1={Path}
{Path} should be a relative path, from the project.properties file to the folder containing the AndroidManifest.xml of the Facebook SDK project. In my case that is ../../build/intermediates/exploded-aar/com.facebook.android/facebook/3.21.0.
Note that this works for all Android Library Projects which contain resources that aren't found by Robolectric. Further reading: here and here. Also, more documentation about project.properties can be found here. Note that in my project the Robolectric tests are located in the Android app project itself. So you could also try placing the project.properties file in the same directory as the AndroidManifest.xml used for testing.
As for your first problem; I have no personal experience with it. But it appears to be because Gradle cannot find the support libraries when compiling the unit tests. The answer from this question should fix it.
Related
When I work with tests - I add class in special module and run test configuration. Class extend (for example) TestCase and work well.
But when I extend UiAutomatorTestCase - I get error
java.lang.RuntimeException: Stub!
at com.android.uiautomator.testrunner.UiAutomatorTestCase.<init> (UiAutomatorTestCase.java:5) ...
My simple class:
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class AutoTest extends UiAutomatorTestCase {
public void testSome() throws UiObjectNotFoundException {
getUiDevice().pressHome();
}
}
How to run it in Android Studio IDE?
Well, if you'd be interested in giving it another try....I was able to get a UIAutomator project started in Android Studio with the following [Github project] (https://github.com/wiliamsouza/bluetooth)
Clone the project locally.
Edit the gradle.properties file to point to your sdk, target and build tools
Import into Android Studio, if prompted be sure to select Gradle.
The accompanying [blog post] (http://wiliamsouza.github.io/#/2013/10/30/android-uiautomator-gradle-build-system) has more details.
I modified with my own test cases and is working well.
I am creating simple android application in android of hello world printing and getting an -- error Description
Resource Path Location Type Error generating final archive: java.lang.ArrayIndexOutOfBoundsException: 13 Demo_ABC Unknown Android Packaging Problem
Code is:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Someone else had the same problem with eclipse. The solution was to check the box "Create Test Project":
Your project is getting associated with some Test Project which you are not mapping with your newly created project. When you are creating any new project check carefully whether you are including the "Create Test Project" option or not.
Another guess: As the error seems to be package-related and your code does not include that, insert the correct package yourpackage.tld; in the code. (you said "Code is:").
Maybe that is missing Android expects it by default and gives weird errors because that was totally unforseen by the Google Android developers.
I have a class set up as an EViewGroup. In it, I'm trying to reference another Activity set up as an EActivity. For some reason, the import isn't resolving, but it resolves fine if I reference the Activity in question from another EActivity.
The code compiles fine using ant on our Jenkins server, but doesn't compile within Ecipse.
Any ideas?
Here's some code for ViewGroup:
import android.app.Activity;
import android.content.Intent;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EViewGroup;
#EViewGroup
public class MainMenu extends SlidingMenu
{
public void navigate(Class<? extends Activity> klass)
{
getContext().startActivity(new Intent(getContext(), klass));
toggle();
}
#Click(R.id.textView_bring_it)
public void bringItClick()
{
navigate(ActivityBringIt_.class);
}
}
The compile errors I'm seeing:
The import com.beachbody.p90x.bringit.ActivityBringIt_ cannot be
resolved
The method navigate(Class) in the type MainMenu
is not applicable for the arguments (Class)
ActivityBringIt_ cannot be resolved to a type
Here is my .factorypath file:
<factorypath>
<factorypathentry kind="WKSPJAR" id="/common/compile-libs/androidannotations-2.7.1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
It seems that ActivityBringIt_ isn't generated. Your compiling errors are just noises because of that.
Mostly AA can't generate subclasses if you have errors in you Android's xml files.
You should take a look on this.
Also, could you copy/paste your .factory file ?
Thanks DayS for pointing me in the right direction. There is a bug in Eclipse causing this issue. The workaround is to import the entire package in question. In my case it is:
import com.beachbody.p90x.bringit.*;
Here is the bug report w/ Eclipse:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387956
I tried a example provided in the, Android app testing through Selenium, i have included the selenium-java library and android-webdriver apk also installed in emulator, but when try with the sample code provide in the forum i got error in AnroidWebDriver import, in selenium library only AndroidDriver class is available, so where could i get the AdroidWebDriver jar. Plz assit.
Note: Selenium library is very latest one.
import android.test.ActivityInstrumentationTestCase2;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidWebDriver;
import simple.app.SimpleAppActivity;
public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> {
private WebDriver driver;
private WebDriver googledriver;
public SimpleGoogleTest() {
super("simple.app", SimpleAppActivity.class);
}
#Override
protected void setUp() throws Exception {
driver = new AndroidWebDriver(getActivity());
}
........................,,,,,
}
There are two variations of the Android Driver:
AndroidDriver() which you use on your Personal Computer e.g. your
laptop, workstation, etc. which provides the richest and most
complete set of capabilities for your tests.
AndroidWebDriver() which runs on your Android device, this wraps a WebView component to provide the basic core functionality.
The example code that comes with the Android SDK and the optional support for Selenium/WebDriver runs some basic tests on the device. The tests are compiled as an Android program which extend ActivityInstrumentationTestCase2. AndroidWebDriver() is contained in sdk/extras/google/webdriver/android_webdriver_library.jar (and the Javadocs are in sdk/extras/google/webdriver/android_webdriver_library-srcs.jar
So, if you want to run your tests on your Android device, then you need to include android-webdriver-library.jar in your project. Perhaps the simplest way is to copy this jar into your test project's libs folder.
However, if you would like to run your tests on your Personal Computer you can modify the example code to use AndroidDriver instead of AndroidWebDriver. You also need to change your base class e.g. to use Junit 3 or Junit 4. I have posted a sample test as an answer to another question on Stack Overflow here Having difficulty in finding Elements using Xpath and CSS in Selenium Android Webdriver Testing
I am trying use the GPE code for App-Android Android-App communication. Both the two new created folders (Android, AppEngine) have errors. I think the problem is that there are
errors with the packages:
import com.google.web.bindery.requestfactory.shared.InstanceRequest;
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.ServiceName;
It says "The import com.google.web cannot be resolved." I tried adding everything able to be checked checked in the build path. I also know I installed the Web Toolkit and everything. What is wrong?
Statements like the following also have error markings:
#ProxyForName(value = "com.glm.server.Message",
locator = "com.glm.server.MessageLocator") and actually there are so many errors it must be the imports.