phuongngacntt / maven-android-plugin

Automatically exported from code.google.com/p/maven-android-plugin
0 stars 0 forks source link

Test of CustomView causes test to fail #460

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Extend the morseflash project with a Custom Android View
2. Extend the tests of the morseflash project tests with a test for 
construction of the customer view
3. Run tests (via mvn clean install in root)

What is the expected output?
All tests Pass

What do you see instead?
Tests hang, or fail.

What version of maven-android-plugin are you using?
3.8.2

What are the complete output lines of "mvn -version" on your machine?
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 
2014-02-14T18:37:52+01:00)
Maven home: /usr/local/apache-maven/apache-maven-3.2.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

Please provide any additional information below.
I decided to try this, as I am investigating the source of this problem with 
the execution of the Instrumentation tests by the android-maven-plugin that I 
have posted on StackOverflow:
http://stackoverflow.com/questions/23204526/androidtestcase-fails-to-find-resour
ce-of-test-project-when-executed-via-maven

I have forked the github samples project and only added the custom view and the 
test for the custom view.
This code can be found here:
https://github.com/andrewdavidmackenzie/maven-android-plugin-samples

Original issue reported on code.google.com by and...@tuenti.com on 29 Apr 2014 at 11:29

GoogleCodeExporter commented 9 years ago
To make it a bit easier to read, this is the code for the test:
public class MorseViewTest extends 
ActivityInstrumentationTestCase2<ConfigureMorseActivity> {

    /**
     * The first constructor parameter must refer to the package identifier of the
     * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
     * file.  This is not necessarily the same as the java package name of the class - in fact, in
     * some cases it may not match at all.
     */
    public MorseViewTest() {
        super("com.simpligility.android.morseflash", ConfigureMorseActivity.class);
    }

    @LargeTest
    public void testCustomView() throws Exception {

        startActivitySync(ConfigureMorseActivity.class);
        Instrumentation instrumentation = getInstrumentation();

        sleep(500); // robotium provides neater ways of waiting for the activity to initialise

        // Create a custom view, using the context of the app under test so that it can find it's
        // layout resources
        MorseFlashCustomView customView = new MorseFlashCustomView(instrumentation.getTargetContext());

        assertNotNull(customView);
    }

    private <T extends Activity> T startActivitySync(Class<T> clazz) {
        Intent intent = new Intent(getInstrumentation().getTargetContext(), clazz);
        intent.setFlags(intent.getFlags() | FLAG_ACTIVITY_NEW_TASK);
        return (T) getInstrumentation().startActivitySync(intent);
    }
}

If I comment out the "startActivitySync" line then it all runs OK.

Original comment by and...@tuenti.com on 29 Apr 2014 at 11:41

GoogleCodeExporter commented 9 years ago
We are no longer using the issue tracking system on Google Code. Please refile 
this issue on https://github.com/jayway/maven-android-plugin/issues if you 
still have this problem with the latest release of the Android Maven Plugin

Original comment by mosa...@gmail.com on 19 May 2014 at 4:20