2011-08-02 24 views
0

我試圖讓Robolectric與位於https://github.com/akquinet/android-archetypes/wiki/Android-release-archetype
我有迄今
1.我已經加入了Robolectric扶養的POM沒有運氣了Android釋放小原型工作。
2.我用的目標「乾淨安裝」
然後我得到錯誤回報這樣的:我如何獲得Robolectric使用Android版本原型?

[ERROR] /Users/Dewi/Dropbox/mac_projects/a-parent/application-it/src/main/java/dsdf/dsfsdf/a/test/ddd.java:[3,16] package org.junit does not exist 
[ERROR] /Users/Dewi/Dropbox/mac_projects/a-parent/application-it/src/main/java/dsdf/dsfsdf/a/test/ddd.java:[4,23] package org.junit.runner does not exist 

是否有人可以嘗試,並獲得該原型使用Maven工作,並告訴我該怎麼辦呢? 這裏是我的測試類:

package dsdf.dsfsdf.a.test; 

import static org.hamcrest.CoreMatchers.equalTo; 
import static org.junit.Assert.assertThat; 

import org.junit.Test; 
import org.junit.runner.RunWith; 

import com.xtremelabs.robolectric.RobolectricTestRunner; 

@RunWith(RobolectricTestRunner.class) 
public class ddd { 
     @Test 
     public void asdasd(){ 
      assertThat(5, equalTo(1)); 
     } 
} 

這裏是我的父POM:

<?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>dsdf.dsfsdf</groupId> 
    <artifactId>a-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 
    <name>a - Parent</name> 

    <modules> 
     <module>application</module> 
     <module>application-it</module> 
    </modules> 

    <dependencies> 
     <dependency> 
      <groupId>com.pivotallabs</groupId> 
      <artifactId>robolectric</artifactId> 
      <version>1.0-RC1</version> 
      <type>jar</type> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.2</version> 
      <type>jar</type> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.hamcrest</groupId> 
      <artifactId>hamcrest-all</artifactId> 
      <version>1.1</version> 
      <type>jar</type> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>com.google.android</groupId> 
       <artifactId>android</artifactId> 
       <version>2.2.1</version> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>com.google.android</groupId> 
       <artifactId>android-test</artifactId> 
       <version>2.2.1</version> 
       <scope>provided</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <build> 
     <pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
        <artifactId>maven-android-plugin</artifactId> 
        <version>2.8.3</version> 
        <inherited>true</inherited> 
        <configuration> 
         <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> 
         <assetsDirectory>${project.basedir}/assets</assetsDirectory> 
         <resourceDirectory>${project.basedir}/res</resourceDirectory> 
         <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> 
         <sdk> 
          <platform>7</platform> 
         </sdk> 
         <deleteConflictingFiles>true</deleteConflictingFiles> 
         <undeployBeforeDeploy>true</undeployBeforeDeploy> 
        </configuration> 
       </plugin> 
       <plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.3.2</version> 
        <inherited>true</inherited> 
        <configuration> 
         <source>1.5</source> 
         <target>1.5</target> 
        </configuration> 
       </plugin> 
       <plugin> 
        <artifactId>maven-enforcer-plugin</artifactId> 
        <version>1.0</version> 
       </plugin> 
       <plugin> 
        <artifactId>maven-release-plugin</artifactId> 
        <version>2.1</version> 
        <configuration> 
         <autoVersionSubmodules>true</autoVersionSubmodules> 
        </configuration> 
       </plugin> 
       <plugin> 
        <artifactId>maven-jarsigner-plugin</artifactId> 
        <version>1.2</version> 
        <inherited>true</inherited> 
        <configuration> 
         <removeExistingSignatures>true</removeExistingSignatures> 
         <archiveDirectory /> 
         <archive>${project.build.directory}/${project.build.finalName}.${project.packaging}</archive> 
         <verbose>true</verbose> 
         <certs>true</certs> 
         <keystore>${sign.keystore}</keystore> 
         <alias>${sign.alias}</alias> 
         <storepass>${sign.storepass}</storepass> 
         <keypass>${sign.keypass}</keypass> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>com.pyx4me</groupId> 
        <artifactId>proguard-maven-plugin</artifactId> 
        <version>2.0.4</version> 
        <dependencies> 
         <dependency> 
          <groupId>net.sf.proguard</groupId> 
          <artifactId>proguard</artifactId> 
          <version>4.4</version> 
          <scope>runtime</scope> 
         </dependency> 
        </dependencies> 
        <configuration> 
         <proguardVersion>4.4</proguardVersion> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <profiles> 
     <profile> 
      <id>release</id> 
      <activation> 
       <property> 
        <name>performRelease</name> 
        <value>true</value> 
       </property> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-enforcer-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>enforce-signing-properties</id> 
           <goals> 
            <goal>enforce</goal> 
           </goals> 
           <configuration> 
            <rules> 
             <requireProperty> 
              <property>sign.keystore</property> 
              <message>The 'sign.keystore' property is missing. It must 
               contain the path to the keystore used to sign the 
               application.</message> 
             </requireProperty> 
             <requireFilesExist> 
              <files> 
               <file>${sign.keystore}</file> 
              </files> 
              <message>The 'sign.keystore' property does not point to a 
               file. It must contain the path to the keystore used to sign 
               the application.</message> 
             </requireFilesExist> 
             <requireProperty> 
              <property>sign.alias</property> 
              <message>The 'sign.alias' property is missing. It must 
               contain the key alias used to sign the application.</message> 
             </requireProperty> 
             <requireProperty> 
              <property>sign.storepass</property> 
              <message>The 'sign.storepass' property is missing. It must 
               contain the password of the keystore used to sign the 
               application. 
         </message> 
             </requireProperty> 
             <requireProperty> 
              <property>sign.keypass</property> 
              <message>The 'sign.keypass' property is missing. It must 
               contain the password of the key used to sign the 
               application.</message> 
             </requireProperty> 
            </rules> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
     <profile> 
      <id>linux</id> 
      <activation> 
       <os> 
        <family>unix</family> 
       </os> 
      </activation> 
      <properties> 
       <rt.jar.path>${java.home}/jre/lib/rt.jar</rt.jar.path> 
       <jsse.jar.path>${java.home}/jre/lib/jsse.jar</jsse.jar.path> 
      </properties> 
     </profile> 
     <!-- mac profile has to be after unix since running on mac will trigger 
      both --> 
     <profile> 
      <id>mac</id> 
      <activation> 
       <os> 
        <family>mac</family> 
       </os> 
      </activation> 
      <properties> 
       <!-- absolute path --> 
       <!--<rt.jar.path>/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar</rt.jar.path> --> 
       <!-- or with JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/ --> 
       <rt.jar.path>${java.home}/../Classes/classes.jar</rt.jar.path> 
       <jsse.jar.path>${java.home}/../Classes/jsse.jar</jsse.jar.path> 
      </properties> 
     </profile> 
     <profile> 
      <id>windows</id> 
      <activation> 
       <os> 
        <family>windows</family> 
       </os> 
      </activation> 
      <properties> 
       <rt.jar.path>${java.home}/jre/lib/rt.jar</rt.jar.path> 
       <jsse.jar.path>${java.home}/jre/lib/jsse.jar</jsse.jar.path> 
      </properties> 
     </profile> 
    </profiles> 

</project> 

,這裏是孩子POM:

<?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> 

    <parent> 
    <groupId>dsdf.dsfsdf</groupId> 
    <artifactId>a-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <groupId>dsdf.dsfsdf</groupId> 
    <artifactId>a-it</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>apk</packaging> 
    <name>a - Integration tests</name> 

    <properties> 
     <!-- 
     When not running a release, we are deploying the plain artifact (so no classifier) 
     This is overridden during the release. 
     --> 
     <zipaligned-classifier></zipaligned-classifier> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>com.google.android</groupId> 
     <artifactId>android</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.google.android</groupId> 
     <artifactId>android-test</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>dsdf.dsfsdf</groupId> 
     <artifactId>a</artifactId> 
     <type>apk</type> 
     <version>0.0.1-SNAPSHOT</version> 
     <classifier>${zipaligned-classifier}</classifier> <!-- classifier set according to the ran profile --> 
    </dependency> 
    <dependency> 
     <groupId>dsdf.dsfsdf</groupId> 
     <artifactId>a</artifactId> 
     <type>jar</type> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
     <artifactId>maven-android-plugin</artifactId> 
     <extensions>true</extensions> 
     </plugin> 
    </plugins> 
    </build> 

    <profiles> 
    <profile> 
     <id>release</id> 
     <properties> 
     <!-- 
      When running a release, we must deployed the final artifact (signed and zipaligned). 
     --> 
     <zipaligned-classifier>aligned</zipaligned-classifier> 
     </properties> 
     <build> 
     <plugins> 
      <plugin> 
      <artifactId>maven-jarsigner-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>sign-application-it-apk</id> 
       <phase>package</phase> 
       <goals> 
        <goal>sign</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
      <plugin> 
      <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
      <artifactId>maven-android-plugin</artifactId> 
      <configuration> 
       <sign> 
       <debug>false</debug> 
       </sign> 
      </configuration> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    </profiles> 

</project> 

感謝

+0

有人嗎? 我已經花了年齡這個:( – dewijones92

回答

0

添加依賴關係的JUnit在pom.xml中

例如:

<dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 
+0

感謝 ,但我已經這樣做了 我知道,我應該已經張貼了我的POMS下手 你能看看有什麼我做錯了嗎? 我已經花了年齡在此 我們非常感謝您的幫助 – dewijones92

0

我是想測試我用同樣的Maven的結構,相同的原型......亂七八糟的應用程序。

顯然,測試範圍不與我的配置工作,因爲,當* - 它模塊是分開的,所執行的主要階段從來沒有像test認爲(如果你檢查日誌,你會看到它缺少,此外,模塊中的src/test/java通常是空的)。

我假定這一點,因爲當我改變都robolectric和JUnit的範圍,「規定」的東西是怎麼回事,但我的測試中正確執行我沒有。有些東西仍然缺失(請參閱my question here)。

我在過去說話,因爲我放棄了將* -it項目合併到主項目中(現在我將離開* -parent)。這很奇怪,因爲我有一個結構非常相似的小庫,它不用退縮就可以運行Instrumentation測試。在這種情況下,主項目不會生成Activity,只是一個簡單的jar庫。