Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wbrunette committed Aug 27, 2018
1 parent c5a0756 commit b512f0d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
package org.opendatakit.sensors;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ServiceTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendatakit.sensors.service.ODKSensorService;

import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertNotNull;


@RunWith(AndroidJUnit4.class)
public class ApplicationTest {

private final static String LOGTAG = ApplicationTest.class.getCanonicalName();

@Rule
public final ServiceTestRule mServiceRule = new ServiceTestRule();

private ODKSensorService bindToService() {
Context context = InstrumentationRegistry.getContext();
Intent bind_intent = new Intent();
bind_intent.setClassName(SensorsConsts.frameworkPackage, SensorsConsts.frameworkService);

int count = 0;
ODKSensorService sensorService;
try {
IBinder service = null;
while ( service == null ) {
try {
service = mServiceRule.bindService(bind_intent);
} catch (TimeoutException e) {
service = null;
}
if ( service == null ) {
++count;
if ( count % 20 == 0 ) {
Log.i(LOGTAG, "bindToDbService failed for " + count);
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
sensorService = ODKSensorService.Stub.asInterface(service);
} catch (IllegalArgumentException e) {
sensorService = null;
}
return sensorService;
}

@Test
public void testBinding() {
ODKSensorService serviceInterface = bindToService();
assertNotNull( "bind did not succeed", serviceInterface);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.opendatakit.sensors;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.junit.Assert.*;

/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
@RunWith(JUnit4.class)
public class ExampleUnitTest {
@Test public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
Expand Down

0 comments on commit b512f0d

Please sign in to comment.