Skip to content

Commit

Permalink
Fix flakey robolectric test.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal committed Aug 18, 2020
1 parent a574fe0 commit 1f1fc94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
20 changes: 15 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ dependencies {

testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.mockito:mockito-core:1.9.5'
testImplementation 'org.powermock:powermock-api-mockito:1.6.5'
testImplementation 'org.powermock:powermock-module-junit4:1.6.5'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.5'
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.5'
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation 'org.powermock:powermock-api-mockito2:1.7.4'
testImplementation 'org.powermock:powermock-module-junit4:1.7.4'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.4'
testImplementation 'org.powermock:powermock-classloading-xstream:1.7.4'

testImplementation 'androidx.test:core:1.2.0'
testImplementation ('org.robolectric:robolectric:4.2') {
Expand Down Expand Up @@ -455,3 +455,13 @@ def getLastCommitTimestamp() {
return os.toString() + "000"
}
}

tasks.withType(Test) {
testLogging {
events "failed"
exceptionFormat "full"
showCauses true
showExceptions true
showStackTraces true
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.thoughtcrime.securesms.conversationlist;

import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;

import androidx.test.core.app.ApplicationProvider;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -33,30 +33,27 @@

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, application = Application.class)
@PowerMockIgnore({ "org.powermock.*", "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" })
@PrepareForTest({ApplicationDependencies.class, DatabaseFactory.class, ThreadDatabase.class})
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" })
@PrepareForTest({ ApplicationDependencies.class, DatabaseFactory.class })
public class UnarchivedConversationListDataSourceTest {

@Rule
public PowerMockRule rule = new PowerMockRule();

private ConversationListDataSource.UnarchivedConversationListDataSource testSubject;

private ThreadDatabase threadDatabase;
private ThreadDatabase threadDatabase;

@Before
public void setUp() {
mockStatic(ApplicationDependencies.class);
mockStatic(DatabaseFactory.class);

final Context context = mock(Context.class);
final ContentResolver contentResolver = mock(ContentResolver.class);
threadDatabase = mock(ThreadDatabase.class);
threadDatabase = mock(ThreadDatabase.class);

when(DatabaseFactory.getThreadDatabase(any())).thenReturn(threadDatabase);
when(context.getContentResolver()).thenReturn(contentResolver);

testSubject = new ConversationListDataSource.UnarchivedConversationListDataSource(context, mock(Invalidator.class));
testSubject = new ConversationListDataSource.UnarchivedConversationListDataSource(ApplicationProvider.getApplicationContext(), mock(Invalidator.class));
}

@Test
Expand Down

0 comments on commit 1f1fc94

Please sign in to comment.