0

私は最近、Android インストルメンテーション テストの使用を試みています。したがって、メインアプリケーションは次の構造を持っています

<?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>com.onestopspot</groupId>
    <artifactId>api_library</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>One Stop Spot</name>

    <dependencies>
        <dependency>
            <groupId>org.springframework.android</groupId>
            <artifactId>spring-android-rest-template</artifactId>
            <version>1.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src/main/java</sourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.4.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <platform>16</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

pm.xml ファイルの構造は次のとおりです。

http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 onestopspot 親 1.0.0-SNAPSHOT com.onestopspot 計測 apk ワン ストップ ショップ - 計測テスト

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android-test</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.onestopspot</groupId>
        <artifactId>api_library</artifactId>
        <version>5.0.0-SNAPSHOT</version>
        <scope>provided</scope>
        <type>apk</type>
    </dependency>

    <dependency>
        <groupId>com.onestopspot</groupId>
        <artifactId>api_library</artifactId>
        <version>5.0.0-SNAPSHOT</version>
        <scope>provided</scope>
        <type>jar</type>
    </dependency>
</dependencies>

<profiles>
    <profile>
        <id>emma</id>
        <dependencies>
            <dependency>
                <groupId>emma</groupId>
                <artifactId>emma</artifactId>
                <type>jar</type>
                <scope>compile</scope>
                <version>2.1.5320</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                    <version>1.0-alpha-1</version>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <goals>
                                <goal>read-project-properties</goal>
                            </goals>
                            <configuration>
                                <files>
                                    <file>project.properties</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <configuration>
                        <test>
                            <coverage>true</coverage>
                            <createReport>true</createReport>
                        </test>
                    </configuration>
                    <extensions>true</extensions>
                    <!-- -->
                    <executions>
                        <execution>
                            <id>pull-coverage</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>pull</goal>
                            </goals>
                            <configuration>
                                <pullSource>/data/data/com.onestopspot.api/files/coverage.ec</pullSource>
                                <pullDestination>${tested.project.dir}/target/emma/coverage.ec</pullDestination>
                            </configuration>
                        </execution>
                    </executions>

                </plugin>
            </plugins>
        </build>
        <reporting>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.maven.plugin</groupId>
                    <artifactId>emma4it-maven-plugin</artifactId>
                    <version>1.3</version>
                    <configuration>
                        <metadatas>${tested.project.dir}/target/emma/coverage.em,${tested.project.dir}/src/
                        </metadatas>
                        <instrumentations>${tested.project.dir}/target/emma/coverage.ec</instrumentations>
                        <reportDirectory>${tested.project.dir}/target/emma/</reportDirectory>
                        <baseDirectory>{tested.project.dir}/target/</baseDirectory>
                        <formats>xml,html</formats>
                    </configuration>
                </plugin>
            </plugins>
        </reporting>
    </profile>
</profiles>

<build>
    <pluginManagement>
        <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>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>

                <test>
                    <skip>false</skip>
                    <!--<instrumentationPackage>packageName</instrumentationPackage> -->
                    <!--<instrumentationRunner>className</instrumentationRunner> -->
                    <!--<debug>true|false</debug> -->
                    <!--<coverage>true|false</coverage> -->
                    <!--<logonly>true|false</logonly> avd -->
                    <!--<testsize>small|medium|large</testsize> -->
                    <testSize>small</testSize>
                    <createReport>true</createReport>
                    <!--<classes> -->
                    <!--<class>your.package.name.YourTestClass</class> -->
                    <!--</classes> -->
                    <!--<packages> -->
                    <!--<package>your.package.name</package> -->
                    <!--</packages> -->
                </test>
            </configuration>
        </plugin>
    </plugins>
</build>

現在、メイン プロジェクトの com.onestopspot.api の下に、Android アプリケーション クラスがあります。onCreate 関数には、アプリケーション クラスが作成されたことを知らせる単純な log.d メッセージがあります。私のテストプロジェクトでは、com.onestopspot.api があり、次のクラスがあります

package com.onestopspot.api;

import junit.framework.Test;
import junit.framework.TestSuite;

import android.test.InstrumentationTestRunner;
import android.test.suitebuilder.TestSuiteBuilder;

public class AllTests extends TestSuite {

    public static Test suite() {
        return new TestSuiteBuilder(AllTests.class)
                .includeAllPackagesUnderHere()
                .build();
    }
}

今、mvn clean install と言うと、次の例外が発生します

[INFO] SH28HTV04654_HTC_HTCOneV :       java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1677)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:371)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4456)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.onestopspot.api.MyApplication
at com.onestopspot.api.ApplicationTests.<init>(ApplicationTests.java:38)
... 18 more

私は何を間違っていますか?私はこれに2日間います。私のプロジェクトはここにあるものとほとんど同じように見えますが、うまくいきませんか? 誰かが私を助けてくれるなら、コードを送ることができますか? 前もって感謝します。

03-16 19:05:11.068: I/TestRunner(9928): failed: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests)
03-16 19:05:11.068: I/TestRunner(9928): ----- begin exception -----
03-16 19:05:11.068: I/TestRunner(9928): java.lang.RuntimeException: Exception during suite construction
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Method.invoke(Method.java:511)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestCase.runTest(TestCase.java:154)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestCase.runBare(TestCase.java:127)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestResult$1.protect(TestResult.java:106)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestResult.runProtected(TestResult.java:124)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestResult.run(TestResult.java:109)
03-16 19:05:11.068: I/TestRunner(9928):     at junit.framework.TestCase.run(TestCase.java:118)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
03-16 19:05:11.068: I/TestRunner(9928):     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1677)
03-16 19:05:11.068: I/TestRunner(9928): Caused by: java.lang.reflect.InvocationTargetException
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Constructor.constructNative(Native Method)
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
03-16 19:05:11.068: I/TestRunner(9928):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:371)
03-16 19:05:11.068: I/TestRunner(9928):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4456)
03-16 19:05:11.068: I/TestRunner(9928):     at android.app.ActivityThread.access$1300(ActivityThread.java:139)
03-16 19:05:11.068: I/TestRunner(9928):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
03-16 19:05:11.068: I/TestRunner(9928):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 19:05:11.068: I/TestRunner(9928):     at android.os.Looper.loop(Looper.java:156)
03-16 19:05:11.068: I/TestRunner(9928):     at android.app.ActivityThread.main(ActivityThread.java:4987)
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 19:05:11.068: I/TestRunner(9928):     at java.lang.reflect.Method.invoke(Method.java:511)
03-16 19:05:11.068: I/TestRunner(9928):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-16 19:05:11.068: I/TestRunner(9928):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-16 19:05:11.068: I/TestRunner(9928):     at dalvik.system.NativeStart.main(Native Method)
03-16 19:05:11.068: I/TestRunner(9928): Caused by: java.lang.NoClassDefFoundError: **com.onestopspot.api.MyApplication**
03-16 19:05:11.068: I/TestRunner(9928):     at com.onestopspot.api.APITest.<init>(APITest.java:38)
03-16 19:05:11.068: I/TestRunner(9928):     ... 18 more
03-16 19:05:11.068: I/TestRunner(9928): ----- end exception -----
03-16 19:05:11.078: I/TestRunner(9928): finished: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests)
03-16 19:05:11.088: I/ActivityManager(1656): Force stopping package com.onestopspot.api uid=10161

com.onestopspot.api.MyApplication は、メイン プロジェクトのアプリケーション クラスです。私の計装プロジェクトはそれを見つけることができないようですか?

4

2 に答える 2

0

これを変更してみてください

  <dependency>
    <groupId>com.onestopspot</groupId>
    <artifactId>api_library</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <scope>provided</scope>
    <type>apk</type>
</dependency>

<dependency>
    <groupId>com.onestopspot</groupId>
    <artifactId>api_library</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <scope>provided</scope>
    <type>jar</type>
</dependency>

<dependency>
    <groupId>com.onestopspot</groupId>
    <artifactId>api_library</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <scope>test</scope>
    <type>apk</type>
</dependency>

<dependency>
    <groupId>com.onestopspot</groupId>
    <artifactId>api_library</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <scope>provided</scope>
</dependency>
于 2014-01-14T08:36:21.567 に答える