2013-01-11 110 views
1

我想知道你们是否知道如何使用Robotium进行BDD测试。Robotium BDD与黄瓜

正如我研究Robotium与不同的虚拟机(Dalvik)一起工作,所以我无法运行Junit测试(仅适用于Android Junit测试)。所以我找到了一个可能的解决方案,用RoboRemote https://github.com/groupon/robo-remote来运行Junit Robotit。但是当我试图与黄瓜融合时,测试变得不稳定。

所以,你们知道使用Robotium进行BDD测试的一些方法吗?

+0

你能给我比多一点点信息它们以何种方式不稳定?他们崩溃?他们失败了很多?请提供更多信息,我会尽力帮助。作为一个便笺,如果你要这样,我会推荐看看https://github.com/calabash-driver/calabash-driver –

回答

2

我已经使用Cucumber-JVM为Android成功集成了Robotium。

有关用于Cucumber-JVM和安装的官方cucumber-android模块的信息,have a look here。您还可以在这里找到有关Cucumber-JVM的API文档和示例:http://cukes.info/platforms.html

在您的应用程序的测试模块中,只需将Robotium Solo jar文件作为依赖项(范围:编译)添加即可。

我的一个测试类的看起来是这样的:

public class CucumberSteps extends ActivityInstrumentationTestCase2<YourActivity> { 

    private Solo solo; 

    public CucumberSteps() { 
    super(YourActivity.class); 
    } 

    @Override 
    protected void setUp() throws Exception { 
    super.setUp(); 
    } 

    @Before 
    public void before() { 
    solo = new Solo(getInstrumentation(), getActivity()); 
    } 

    @After 
    public void after() throws Throwable { 
    //clean up 
    solo.finalize(); 
    } 

    @Override 
    protected void tearDown() throws Exception { 
    solo.finishOpenedActivities(); 
    super.tearDown(); 
    } 

    @Given("^step_given_description$") 
    public void step_given_description() throws Throwable { 
    final View testView = solo.getView(R.id.testView); 
    solo.waitForView(testView); 
    solo.clickOnView(testView); 
    // and so on 
    } 
} 

我希望这是足够的信息,任何人都可以上手。当问这个问题时,cucumber-android还没有存在。请记住,GUI测试通常有点不稳定!我设法在本地获得一组稳定的测试,但例如在詹金斯,通常一些测试失败的原因不明。

+0

嘿Blacklight,你能告诉我你是怎么用Android运行黄瓜的?我们即将整合黄瓜+ android + maven,但总是失败,因为没有找到类。 maven无法找到黄瓜亚军类(正常instamentation测试它运作良好)。你能帮助我们吗? – Karoly

1

我知道这是一个非常古老的问题,但有关此主题的文档非常有限,所以我会发布另一条信息。

这篇文章对我帮助很大:http://www.opencredo.com/2014/01/28/cucumber-android-vs-cucumber-appium/

而且我这里使用的文档,以及(我知道这是不推荐使用,但主要项目有没有关于Android文档的话):https://github.com/mfellner/cucumber-android

我得到了它与13的IntelliJ社区版和Maven使用位来自Android的 引导工作 - http://www.androidbootstrap.com/(主要是Maven的集成测试项目配置)

希望它能帮助。

0

我得到了工作与黄瓜JVM robotium和androidstudio使用这个亚军:“不稳定”

import android.os.Bundle; 

    import cucumber.api.CucumberOptions; import 
    cucumber.api.android.CucumberInstrumentation; 


    @CucumberOptions(features = {"features"}, tags = {"@smoke", 
    "[email protected]", "[email protected]", "[email protected]"}) 

    public class Instrumentation extends CucumberInstrumentation { 

     private final CucumberInstrumentation instrumentationCore = new CucumberInstrumentation(); 

     @Override 
     public void onCreate(final Bundle bundle) { 
      super.onCreate(bundle); 
      instrumentationCore.onCreate(bundle); 
      start(); 
     } 

     @Override 
     public void onStart() { 
      waitForIdleSync(); 
      instrumentationCore.start(); 
     } 
    }