Android测试:如何测试createChooser是否已打开

时间:2015-08-08 04:49:02

标签: android automated-tests robotium

我的应用程序有一个共享选项,我试图测试"选择一个应用程序来共享"活动开了。我可以看到它在我的平板电脑上打开,但它没有被我的测试所吸引。已经尝试了几种可能的方法,包括此处发布的建议

How to check ACTION_SEND intent is started?

但似乎没有任何效果。请帮我弄清楚出了什么问题。 谢谢!

的活动:

char* field(){
     char* out;
     float* fOut;

     //Get the return type
     switch(getType(0)){ //This isn't needed, just ignore it :)
     case Integer:
        out = getInt(5);//int getInt(int test) { return test; }
     break;
     case Float:
        out = getFloat(1.7f);//int getFloat(float test) { return test; }
     break;
     case String:
        out = getString(":(");//int getString(char* test) { return test; }
     break;
     case Vector:
        getVector(0);//int getString(float* test) { return test; }
     break;
     }

     return out;
}

测试:

Intent intencao = new Intent(Intent.ACTION_SEND);  
intencao.setType("text/plain");
intencao.putExtra(Intent.EXTRA_SUBJECT, "Horários de ônibus offline em NH");
String strAux = "Experimente esse App\n\n";
strAux += "https://play.google.com/store/apps/details?id=br.com.solenoide.onibus \n\n";
intencao.putExtra(Intent.EXTRA_TEXT, strAux);
startActivity(Intent.createChooser(intencao, "Escolha como compartilhar"));

1 个答案:

答案 0 :(得分:0)

您可以使用this

之类的内容
final Intent launchIntent = getStartedActivityIntent();
assertNotNull("Intent was null", launchIntent);

final String payload =
        launchIntent.getStringExtra(NextActivity.EXTRAS_PAYLOAD_KEY);
assertEquals("Payload is empty", LaunchActivity.STRING_PAYLOAD, payload);