2013-01-11 111 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(); 
     } 
    }