Fix flakey robolectric test.

master
Alan Evans 2020-08-18 11:57:35 -03:00 committed by GitHub
parent a574fe026c
commit 1f1fc94d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -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') {
@ -455,3 +455,13 @@ def getLastCommitTimestamp() {
return os.toString() + "000"
}
}
tasks.withType(Test) {
testLogging {
events "failed"
exceptionFormat "full"
showCauses true
showExceptions true
showStackTraces true
}
}

View File

@ -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;
@ -33,8 +33,8 @@ import static org.powermock.api.mockito.PowerMockito.when;
@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
@ -42,21 +42,18 @@ public class UnarchivedConversationListDataSourceTest {
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