Added Android JUnit test project

This commit is contained in:
Sylvain Berfini 2012-09-07 10:01:32 +02:00
parent a3b9b544e6
commit f6ea7e5158
20 changed files with 245 additions and 3 deletions

View file

@ -151,7 +151,10 @@ public class HistorySimpleFragment extends Fragment implements OnClickListener,
} else {
address = log.getTo();
}
LinphoneActivity.instance().displayHistoryDetail(address.asStringUriOnly(), log);
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayHistoryDetail(address.asStringUriOnly(), log);
}
}
}

View file

@ -127,8 +127,8 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
public void logIn(String username, String password, String domain) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
if (imm != null && getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
saveCreatedAccount(username, password, domain);

14
tests/.classpath Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry combineaccessrules="false" kind="src" path="/linphone-android-newUI"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="lib" path="libs/robotium-solo-3.4.1.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/linphone-android-test/libs/robotium-solo-3.4.1-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

34
tests/.project Normal file
View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>linphone-android-test</name>
<comment></comment>
<projects>
<project>linphone-android-newUI</project>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

19
tests/AndroidManifest.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="org.linphone" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>

1
tests/README Normal file
View file

@ -0,0 +1 @@
This is a JUnit test project for Linphone's Android application.

View file

@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

14
tests/project.properties Normal file
View file

@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Linphone-android-testTest</string>
</resources>

View file

@ -0,0 +1,83 @@
package org.linphone.test;
import junit.framework.Assert;
import org.linphone.LinphoneActivity;
import org.linphone.R;
import org.linphone.setup.SetupActivity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;
import android.widget.ListView;
import com.jayway.android.robotium.solo.Solo;
public class AccountsTest extends
ActivityInstrumentationTestCase2<LinphoneActivity> {
private Solo solo;
@SuppressWarnings("deprecation")
public AccountsTest() {
super("org.linphone", LinphoneActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void testConfigureExistingAccount() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
int nbAccountsBefore = prefs.getInt(getActivity().getString(R.string.pref_extra_accounts), 0);
solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class);
solo.clickOnView(solo.getView(R.id.settings));
solo.clickOnText("Account Setup Assistant");
solo.assertCurrentActivity("Expected Setup Activity", SetupActivity.class);
solo.clickOnView(solo.getView(R.id.setup_next));
solo.clickOnText("I already have a linphone.org account");
solo.enterText((EditText) solo.getView(R.id.setup_username), "wizard15");
solo.enterText((EditText) solo.getView(R.id.setup_password), "wizard15");
solo.clickOnText("Apply");
solo.waitForActivity("LinphoneActivity", 2000);
Assert.assertTrue(solo.searchText("wizard15@sip.linphone.org"));
int nbAccountsAfter = prefs.getInt(getActivity().getString(R.string.pref_extra_accounts), 0);
Assert.assertEquals(nbAccountsBefore + 1, nbAccountsAfter);
}
public void testDeleteConfiguredAccount() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
int nbAccountsBefore = prefs.getInt(getActivity().getString(R.string.pref_extra_accounts), 0);
solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class);
solo.clickOnView(solo.getView(R.id.settings));
Assert.assertTrue(solo.searchText("wizard15@sip.linphone.org"));
solo.clickOnText("wizard15@sip.linphone.org");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ListView list = (ListView) solo.getView(android.R.id.list);
list.setSelection(7);
}
});
solo.clickOnText("Delete this account");
int nbAccountsAfter = prefs.getInt(getActivity().getString(R.string.pref_extra_accounts), 0);
Assert.assertEquals(nbAccountsBefore - 1, nbAccountsAfter);
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}

View file

@ -0,0 +1,48 @@
package org.linphone.test;
import junit.framework.Assert;
import org.linphone.InCallActivity;
import org.linphone.LinphoneActivity;
import org.linphone.R;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;
import com.jayway.android.robotium.solo.Solo;
public class CallTest extends
ActivityInstrumentationTestCase2<LinphoneActivity> {
private Solo solo;
@SuppressWarnings("deprecation")
public CallTest() {
super("org.linphone", LinphoneActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void testOutgoingCallToCotcot() {
solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class);
solo.clickOnView(solo.getView(R.id.Adress));
solo.enterText((EditText) solo.getView(R.id.Adress), "cotcot@sip.linphone.org");
solo.clickOnView(solo.getView(R.id.Call));
solo.waitForActivity("InCallActivity", 2000);
solo.assertCurrentActivity("Expected InCall Activity", InCallActivity.class);
Assert.assertTrue(solo.searchText("Simon MORLAT"));
}
@Override
public void tearDown() throws Exception {
solo.clickOnView(solo.getView(R.id.hangUp));
solo.waitForActivity("LinphoneActivity", 2000);
solo.finishOpenedActivities();
}
}