【问题标题】:install robolectric with maven and eclipse for android testing使用 maven 和 eclipse 安装 robolectric 以进行 android 测试
【发布时间】:2014-04-15 17:02:40
【问题描述】:

我在互联网上花了四个多小时寻找在 Eclipse/Maven 中安装 Robolectric 的方法/教程/指南,但我没有找到任何具体的东西。

我尝试通过在POM中添加依赖,它不起作用。

我也尝试在本地安装它(创建一个新的 java 项目并链接到测试文件夹)只是为了测试它,但它不能正常工作(因为应用程序是一个 maven 应用程序)。

有人可以帮助我吗? 感谢您的宝贵时间。

【问题讨论】:

    标签: android eclipse maven robolectric


    【解决方案1】:

    我昨天刚做的:)

    这是我必须添加到我的 pom.xml 中的内容

    部分版本

    <fest-android.version>1.0.7</fest-android.version>
    <robolectric.version>2.2</robolectric.version>
    <junit.version>4.8.2</junit.version>
    <android.test.version>4.2.2_r2</android.test.version>
    

    一些依赖项

    <!-- Test Dependencies  -->
    <dependency>
      <groupId>com.squareup</groupId>
      <artifactId>fest-android</artifactId>
      <version>${fest-android.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.robolectric</groupId>
        <artifactId>robolectric</artifactId>
        <version>${robolectric.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
         <groupId>android</groupId>
         <artifactId>android</artifactId>
         <version>${android.test.version}</version>
         <scope>provided</scope>
     </dependency>
    

    显然,如果你不使用 fest-android,你的 pom 中就不需要版本和依赖。

    build 标签中的 Surefire

    <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.6</version>
          <configuration>
              <argLine>-Xmx1024m</argLine>
          </configuration>
      </plugin>
    

    指向您的测试文件夹

    默认情况下,surefire 在 /src/test/java 中查找测试类,但是如果您更改了它,请将结束 build 标记之前的测试文件夹配置为:

    <testSourceDirectory>test</testSourceDirectory>
    

    完成!

    干杯。

    【讨论】:

    【解决方案2】:

    这是m2e-android 的一个已知问题,将在下一个版本中修复:

    https://github.com/rgladwell/m2e-android/issues/52

    请关注my Twitter feed 或订阅Maven Android Developers mailing list 以获取更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      相关资源
      最近更新 更多