Click here to Skip to main content
14,930,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a share button and on clicking that you have share app link option where you can share in various app. So I just wanted to test this sharing app. I am new in the android and till now I did not got any good material related to this topic and if got then not understood that much.

Code for share app
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sharebtn = findViewById(R.id.sharebtn);
sharebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent shareintent = new Intent(Intent.ACTION_SEND);
shareintent.setType("text/plain");
String shareBody = "Download this one : https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en_IN&gl=US";
String sharesubject = "learning the share app";

shareintent.putExtra(Intent.EXTRA_SUBJECT,sharesubject);
shareintent.putExtra(Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(shareintent,"Share Using"));

//startActivity(shareintent);
}
});
}

What I have tried:

I have done testing of dialer with code like that

onView(withId(R.id.button)).perform(click());

intended(allOf( hasAction(Intent.ACTION_DIAL), hasData(INTENT_DATA_PHONE_NUMBER), toPackage(PACKAGE_ANDROID_DIALER)));

I was thinking similar to this only in share app also by replacing Intent.ACTION_DIAL to Intent.ACTION_SEND and INTENT_DATA_PHONE_NUMBER to MESSAGE_TO_SENT but not succeeded and later come to know that share app do not have any package as package is related to app only. So I just wanted to know that how can I write the UI test case for share app.
Posted
Comments
David Crow 29-Apr-21 22:07pm
   
"...how can I write the UI test case for share app."

Your question is unclear. Since you are writing the code and therefore know what it is supposed to do, the test case is simply "Does it do it?"

When you click the sharebtn button, does the above code show up? In other words, do you get a "Share Using" dialog?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900