如何使用cucumber-java在intellij 13.1.4中为android项目设置和运行黄瓜bdd测试

时间:2014-09-12 15:23:39

标签: java android intellij-idea

Intellij IDE原生支持黄瓜。但问题是我正在尝试在intellij 13.1.4 IDE中的android项目上创建并运行黄瓜测试。 经过大量研究后,我遇到了this教程。但在遵循它并运行我的测试后,我得到了这个结果

Running tests
Test running 
startedTest 
running failed: Unable to find instrumentation info for: ComponentInfo{com.test.cucumbertest.apptest/cucumber.api.android.CucumberInstrumentation}
Empty test suite.

这是我项目的结构 CucumberTest | app | libs | | cucumber-android-1.1.8.jar | cucumber-core-1.1.8.jar | cucumber-html-0.2.3.jar | cucumber-java-1.1.8.jar | gherkin-2.11.2.jar | junit-4.11.jar src | androidTest | | java | | com.test.cucumbertest.app | | MyStepsDefs.java | | RunTest.java | | testclass.feature | main | java | com.test.cucumbertest.app | MainActivity.java

MyStepDefs.java

package com.test.cucumbertest.app;

import android.test.ActivityInstrumentationTestCase2;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;

public class MyStepDefs extends ActivityInstrumentationTestCase2<MainActivity>{
    public MyStepDefs() {
        super(MainActivity.class);
    }
    @Given("^I have lunch the app$")
    public void I_have_lunch_the_app() throws Throwable {
        // Express the Regexp above with the code you wish you had
        assertTrue(true);
    } 

}

RunTest.java:

package com.test.cucumbertest.app;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(format = {"pretty", "html:report"})
public class RunTest {

}

testclass.feature:

Feature: Test BDD
  Scenario: Scenario One
    Given I have lunch the app

我做错了什么?

这是我的AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.cucumbertest.app" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.test.cucumbertest.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我正在使用gradle

1 个答案:

答案 0 :(得分:1)

我提示您提供类似的消息。不同的是我使用Android Studio。 您可以尝试通过

将instrumentation标记添加到AndroidManifest.xml中
<instrumentation
        android:name="cucumber.api.android.CucumberInstrumentation"
        android:targetPackage="com.test.cucumbertest.app"
/>

但是,我猜你发布的消息中有拼写错误?(&#34; com.test.cucumbertest.apptest&#34; =&gt;&#34; com.test.cucumbertest.app.test&#34; )

如果错误仍然提示,您可能还需要将测试包重命名为&#34; com.test.cucumbertest.app.test&#34;