Created
September 14, 2016 09:55
-
-
Save esmasui/5ec4a9fe86ee2be220f2ca6370cc81f7 to your computer and use it in GitHub Desktop.
UnitTestで@smallTestとかでフィルターする例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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