sow*_*mia 1 android android-testing cucumber-jvm
使用:带有Android Instrumentation + Espresso的Cucumber-JVM).
参考Github链接:https://github.com/mfellner/cucumber-android.简单的样本工作正常.
使用cucumber-jvm + android检测问题: 但是在链接中的示例中,它使用了不推荐使用的ActivityInstrumentationTestCase2.我想使用谷歌所说的@Rule - ActivityTestRule类.
这里我的问题是: 对于使用cucumber-jvm,我使用的是CucumberInstrumentationCore而不是testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner".
因此,像@Rule for ActivityTestRule的Android junit注释不会被CucumberInstrumentation解析.那么有可能克服这个问题吗?
然后我决定使用cucumber-jvm + android工具必须恢复原状.我的问题不仅仅是对于已弃用的类,而且全局是使用cucumber-jvm + android检测的好主意,因为它因为注释解析而无法使用检测功能.
Sag*_*ovo 10
你的跑步者应该继承Android JUnitRunner:
public class Instrumentation extends AndroidJUnitRunner {
private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);
@Override
public void onCreate(final Bundle bundle) {
instrumentationCore.create(bundle);
super.onCreate(bundle);
}
@Override
public void onStart() {
waitForIdleSync();
instrumentationCore.start();
}
Run Code Online (Sandbox Code Playgroud)
注意在onCreate结束时初始化的超类.
然后,在build.grade文件中编辑defaultConfig:
defaultConfig {
applicationId "your.package.name"
testApplicationId "your.steps.package"
testInstrumentationRunner "your.package.Instrumentation"
}
Run Code Online (Sandbox Code Playgroud)
最后,继承自ActivityInstrumentationTestCase2的步骤定义类应如下所示:
public class BaseStepDefinitions {
public static final String TAG = BaseStepDefinitions.class.getSimpleName();
@Rule
public ActivityTestRule<StartupActivity> mActivityRule = new ActivityTestRule<>(StartupActivity.class);
@Before
public void setUp() throws Exception {
mActivityRule.launchActivity(null);
mActivityRule.getActivity();
}
/**
* All the clean up of application's data and state after each scenario must happen here
*/
@After
public void tearDown() throws Exception {
}
@When("^I login with \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_login_with_and(String user, String password) throws Throwable {
// Login...
}
Run Code Online (Sandbox Code Playgroud)
setUp函数在每个场景之前运行,并启动活动.
在全球范围内,如果它满足您的需求,我没有看到任何使用它的问题,可以通过这种方式解析Cucumber注释和JUnit注释.
我创建了一个示例项目:github.com/Clutcha/EspressoCucumber
| 归档时间: |
|
| 查看次数: |
1761 次 |
| 最近记录: |