Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:46:16+00:00 2026-06-13T22:46:16+00:00

I setup an Android test project by Maven and followed the instructions from here

  • 0

I setup an Android test project by Maven and followed the instructions from here.
Basically I was able to setup the test project, even the emulator is being recognized, but I still can’t run the tests by Maven when executing mvn install (in Eclipse). If I try to execute it, I get the following errors:


Failed tests: warning(junit.framework.TestSuite$1): Exception in constructor: testPersistAndRead (java.lang.RuntimeException: Stub!(..)
warning(junit.framework.TestSuite$1): Exception in constructor: testFileNotExists (java.lang.RuntimeException: Stub!(..)
warning(junit.framework.TestSuite$1): Exception in constructor: testCreateFiles (java.lang.RuntimeException: Stub!(..)
warning(junit.framework.TestSuite$1): Exception in constructor: testFilesExist (java.lang.RuntimeException: Stub!(..)
warning(junit.framework.TestSuite$1): Exception in constructor: testAndroidTestCaseSetupProperly (java.lang.RuntimeException: Stub!(..)

The output from surfire tells me that it is nested in AndroidTestCase:


junit.framework.AssertionFailedError: Exception in constructor: testPersistAndRead (java.lang.RuntimeException: Stub!
at android.test.AndroidTestCase.(AndroidTestCase.java:5)
[…]

This is the test I try to run.

public class PersistenceManagerTest extends AndroidTestCase {

    private final String FILENAME_PREFIX = "test.";

    protected void setUp() throws Exception {
        super.setUp();
        deleteInternalStorageFile();

        MockContentResolver resolver = new MockContentResolver();
        RenamingDelegatingContext renamingDelegatingContext = new RenamingDelegatingContext(new MockContext(), getContext(), FILENAME_PREFIX);
        Context context = new IsolatedContext(resolver, renamingDelegatingContext);

        setContext(context);
    }

    //AfterClass
    protected void tearDown() {
        deleteInternalStorageFile();
    }

    public void testPersistAndRead() throws IOException {
        String testData = "foobar";

        PersistenceManager.persist(testData, FileType.JSONDATA);

        String result = PersistenceManager.getFileData(FileType.JSONDATA);

        assertEquals(testData, result);
    }

    public void testFileNotExists()  {
        try {
            PersistenceManager.getFileData(FileType.JSONDATA);
            fail("PersistenceManager.getFileData should throw an exception!");
        } 
        catch (IOException e) {
            //expected
        }
    }

    public void testCreateFiles()  {
        try {
            PersistenceManager.createNewFiles();
        } 
        catch (IOException e) {
            fail("PersistenceManager.createNewFiles() threw an exception");
        }   
        try {
            PersistenceManager.getFileData(FileType.JSONDATA);
        } 
        catch (IOException e) {
            fail("PersistenceManager.getFileData should not throw an exception!");
        }
    }

    public void testFilesExist() throws IOException  {
        assertFalse(PersistenceManager.filesExist());

        PersistenceManager.createNewFiles();

        assertTrue(PersistenceManager.filesExist());
    }

    private void deleteInternalStorageFile() {
        getContext().deleteFile(PersistenceManager.JSONDATAFILE);
        getContext().deleteFile(PersistenceManager.TIMESTAMPFILE);
    }
}

…and this is the pom.xml from the test project.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>
    <modelVersion>4.0.0</modelVersion>
    <groupId>net.mydomain.android</groupId>
    <artifactId>myproject-androidtests</artifactId>
    <packaging>apk</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Testproject</name>

    <properties>
        <platform.version>2.1.2</platform.version>
        <android.sdk.path>/opt/android-sdk-linux</android.sdk.path>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <android.device>emulator</android.device>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android-test</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>net.mydomain.android</groupId>
            <artifactId>myartifact</artifactId>
            <type>apk</type>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>net.mydomain.android</groupId>
            <artifactId>myartifact</artifactId>
            <scope>provided</scope>
            <type>jar</type>
            <version>1.0-SNAPSHOT</version>
        </dependency>

    </dependencies>
    <build>
        <outputDirectory>bin/classes</outputDirectory>
        <testOutputDirectory>bin/test-classes</testOutputDirectory>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <sdk>
                        <path>${android.sdk.path}</path>
                        <platform>7</platform>
                    </sdk>
                </configuration>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

Any ideas why this isn’t working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:46:17+00:00Added an answer on June 13, 2026 at 10:46 pm

    I found the solution here.

    dtmilano’s answer is basically not wrong, but I didn’t know what that means for my test. The solution is to tell Maven that instrumentation tests must not be run as JUnit tests, so the instrumentation tests must not be in src/test/java but in src/main/java. Instead they have to be included into the apk, so they are getting deployed on the device and triggered to run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup an android test project that runs junit tests. It's using two
tesseract-android-tools-test (test project to ensure everything is set up right) works. i got my
i have to setup an android maven build for a customer, which previously was
First to explain how projects are setup: Android Library project with two classes: UserActivity
I have an android lib project, and an android test project i've built in
I have a JUnit test case in an Android project that contains code that
I am trying to setup local CI environment - an Android project, built with
I tried to use Proguard in my Android project, i setup Proguard using command
After following some instructions on Diego Torres blog I am able to test my
I've setup an Android-x86 image (4.0-RC1-eeepc) in VirtualBox on a Dell Latitude D820. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.