Skip to content

Commit

Permalink
test: address flaky unit tests found on browserstack (#483)
Browse files Browse the repository at this point in the history
test: address flaky unit tests found on browserstack
  • Loading branch information
fractalwrench committed May 16, 2019
2 parents a86c8f6 + 28bbfa5 commit 2674dfd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 65 deletions.

This file was deleted.

Expand Up @@ -44,10 +44,13 @@ static SharedPreferences getSharedPrefs(Context context) {
return context.getSharedPreferences("com.bugsnag.android", Context.MODE_PRIVATE);
}

static Client generateClient(Configuration config) {
config.setDelivery(generateDelivery());
return new Client(InstrumentationRegistry.getTargetContext(), config);
}

static Client generateClient() {
Client client = new Client(InstrumentationRegistry.getContext(), "api-key");
client.config.setDelivery(generateDelivery());
return client;
return generateClient(new Configuration("api-key"));
}

static Session generateSession() {
Expand Down
9 changes: 7 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
@@ -1,6 +1,7 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.generateConfiguration;
import static com.bugsnag.android.BugsnagTestUtils.getSharedPrefs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -229,7 +230,9 @@ public void testFullManifestConfig() {
@SuppressWarnings("deprecation") // test backwards compatibility of client.setMaxBreadcrumbs
@Test
public void testMaxBreadcrumbs() {
client = generateClient();
Configuration config = generateConfiguration();
config.setAutomaticallyCollectBreadcrumbs(false);
client = generateClient(config);
assertEquals(0, client.breadcrumbs.store.size());

client.setMaxBreadcrumbs(1);
Expand All @@ -246,7 +249,9 @@ public void testMaxBreadcrumbs() {

@Test
public void testClearBreadcrumbs() {
client = generateClient();
Configuration config = generateConfiguration();
config.setAutomaticallyCollectBreadcrumbs(false);
client = generateClient(config);
assertEquals(0, client.breadcrumbs.store.size());

client.leaveBreadcrumb("test");
Expand Down
17 changes: 0 additions & 17 deletions sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java
Expand Up @@ -129,23 +129,6 @@ public void isStartupCrash() throws Exception {
assertFalse(errorStore.isStartupCrash(10000));
}

@Test
public void testFindStoredFiles() {
assertEquals(0, errorStore.queuedFiles.size());
writeErrorToStore();
assertEquals(0, errorStore.queuedFiles.size());

List<File> storedFiles = errorStore.findStoredFiles();
assertEquals(1, storedFiles.size());
assertEquals(1, errorStore.queuedFiles.size());

writeErrorToStore();
writeErrorToStore();
storedFiles = errorStore.findStoredFiles();
assertEquals(2, storedFiles.size());
assertEquals(3, errorStore.queuedFiles.size());
}

@Test
public void testCancelQueuedFiles() {
assertEquals(0, errorStore.queuedFiles.size());
Expand Down
Expand Up @@ -25,6 +25,7 @@ public class NullMetadataTest {

private Configuration config;
private Throwable throwable;
private Client client;

/**
* Generates a bugsnag client with a NOP error api client
Expand All @@ -34,7 +35,7 @@ public class NullMetadataTest {
@Before
public void setUp() throws Exception {
config = new Configuration("api-key");
generateClient();
client = generateClient(config);
throwable = new RuntimeException("Test");
}

Expand Down Expand Up @@ -94,7 +95,7 @@ public void testConfigSetNullMetadata() throws Exception {

@Test
public void testNotify() throws Exception {
Bugsnag.beforeNotify(new BeforeNotify() {
client.beforeNotify(new BeforeNotify() {
@Override
public boolean run(@NonNull Error error) {
validateDefaultMetadata(error.getMetaData());
Expand All @@ -103,7 +104,6 @@ public boolean run(@NonNull Error error) {
});
Error error = new Error.Builder(config, new Throwable(),
generateSessionTracker(), Thread.currentThread(), false).build();
Client client = Bugsnag.getClient();
client.notify(error, DeliveryStyle.SAME_THREAD, null);
}

Expand Down

0 comments on commit 2674dfd

Please sign in to comment.