Skip to content
Snippets Groups Projects
Commit 307cec20 authored by John Carlson's avatar John Carlson
Browse files

Add a Robolectric test for testing login.

parent 53487648
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -10,8 +10,9 @@ android {
applicationId "com.commit451.gitlab"
minSdkVersion 16
targetSdkVersion 23
versionCode 220
versionName "2.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 221
versionName "2.2.1"
}
buildTypes {
release {
Loading
Loading
@@ -34,6 +35,8 @@ android {
 
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
Loading
Loading
Loading
Loading
@@ -39,11 +39,7 @@ public class GitLabApp extends Application {
sInstance = this;
 
forceLocale(Locale.ENGLISH);
CrashlyticsCore core = new CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
.build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
setupCrashReporting();
 
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
Loading
Loading
@@ -52,6 +48,13 @@ public class GitLabApp extends Application {
JodaTimeAndroid.init(this);
}
 
protected void setupCrashReporting() {
CrashlyticsCore core = new CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
.build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
}
private void forceLocale(Locale locale){
try {
Locale.setDefault(locale);
Loading
Loading
package com.commit451.gitlab;
import android.net.Uri;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.model.api.UserLogin;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import java.util.List;
import retrofit.Response;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Tests account login and basic retrieval stuff
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class LoginUnitTest {
@Test
public void loginTest() throws Exception {
Account testAccount = getTestAccount();
Response<UserLogin> loginResponse = GitLabClient.instance(testAccount)
.loginWithUsername("TestAllTheThings", "testing123")
.execute();
assertTrue(loginResponse.isSuccess());
assertNotNull(loginResponse.body().getPrivateToken());
//attach the newly retrieved private token
testAccount.setPrivateToken(loginResponse.body().getPrivateToken());
GitLabClient.setAccount(testAccount);
Response<List<Project>> projectsResponse = GitLabClient.instance()
.getAllProjects()
.execute();
assertTrue(projectsResponse.isSuccess());
assertNotNull(projectsResponse.body());
}
public static Account getTestAccount() {
Account account = new Account();
account.setServerUrl(Uri.parse("https://gitlab.com"));
return account;
}
}
\ No newline at end of file
package com.commit451.gitlab;
import org.robolectric.TestLifecycleApplication;
import java.lang.reflect.Method;
/**
* Test version of our Application class, used by Robolectric
*/
public class TestGitLabApp extends GitLabApp implements TestLifecycleApplication {
@Override
public void beforeTest(Method method) {
}
@Override
public void prepareTest(Object test) {
}
@Override
public void afterTest(Method method) {
}
@Override
protected void setupCrashReporting() {
//Intentionally left blank
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment