Skip to content

Instantly share code, notes, and snippets.

@esmasui
Created September 14, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmasui/5ec4a9fe86ee2be220f2ca6370cc81f7 to your computer and use it in GitHub Desktop.
Save esmasui/5ec4a9fe86ee2be220f2ca6370cc81f7 to your computer and use it in GitHub Desktop.
UnitTestで@smallTestとかでフィルターする例
package com.example;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
@RunWith(MyRunner.class)
public class ExampleUnitTest {
@Test
@SmallTest
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
package com.example;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import java.lang.annotation.Annotation;
/**
* Created by masui on 9/14/16.
*/
public class MyRunner extends BlockJUnit4ClassRunner {
public MyRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
for (Annotation annotation : description.getAnnotations()) {
if(SmallTest.class.isInstance(annotation)){
notifier.fireTestIgnored(description);
return;
}
}
super.runChild(method, notifier);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment