diff options
author | Julien Desprez <jdesprez@google.com> | 2017-05-26 15:32:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-05-26 15:32:10 +0000 |
commit | d3a59810693f3150d25699d6505a36b246d9191d (patch) | |
tree | 6262b22b124f4150e90cc44dd5a728d34ec42f9c | |
parent | 4d2178ef37caa168c8ac7a8a60782fbbe75dc9ce (diff) | |
parent | 2c4591907a2eedff5b90276dfe9004ab6bcfeb2a (diff) | |
download | tradefederation-d3a59810693f3150d25699d6505a36b246d9191d.tar.gz |
Merge "Complete event lifecycle for @Ignore" into oc-dev
-rw-r--r-- | src/com/android/tradefed/result/JUnit4ResultForwarder.java | 4 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/testtype/HostTestTest.java | 51 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/com/android/tradefed/result/JUnit4ResultForwarder.java b/src/com/android/tradefed/result/JUnit4ResultForwarder.java index 2ee53e29a..f3cfd52e0 100644 --- a/src/com/android/tradefed/result/JUnit4ResultForwarder.java +++ b/src/com/android/tradefed/result/JUnit4ResultForwarder.java @@ -68,6 +68,10 @@ public class JUnit4ResultForwarder extends RunListener { public void testIgnored(Description description) throws Exception { TestIdentifier testid = new TestIdentifier(description.getClassName(), description.getMethodName()); + // We complete the event life cycle since JUnit4 fireIgnored is not within fireTestStarted + // and fireTestEnded. + mListener.testStarted(testid); mListener.testIgnored(testid); + mListener.testEnded(testid, Collections.emptyMap()); } } diff --git a/tests/src/com/android/tradefed/testtype/HostTestTest.java b/tests/src/com/android/tradefed/testtype/HostTestTest.java index 55c929730..fd8021d9c 100644 --- a/tests/src/com/android/tradefed/testtype/HostTestTest.java +++ b/tests/src/com/android/tradefed/testtype/HostTestTest.java @@ -29,6 +29,7 @@ import junit.framework.TestSuite; import org.easymock.Capture; import org.easymock.EasyMock; import org.junit.Before; +import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite.SuiteClasses; @@ -121,6 +122,34 @@ public class HostTestTest extends TestCase { } } + /** + * Test class, we have to annotate with full org.junit.Test to avoid name collision in import. + * And with one test marked as Ignored + */ + @RunWith(DeviceJUnit4ClassRunner.class) + public static class Junit4TestClassWithIgnore implements IDeviceTest { + private ITestDevice mDevice; + + public Junit4TestClassWithIgnore() {} + + @org.junit.Test + public void testPass5() {} + + @Ignore + @org.junit.Test + public void testPass6() {} + + @Override + public void setDevice(ITestDevice device) { + mDevice = device; + } + + @Override + public ITestDevice getDevice() { + return mDevice; + } + } + @RunWith(DeviceSuite.class) @SuiteClasses({ Junit4TestClass.class, @@ -738,6 +767,28 @@ public class HostTestTest extends TestCase { } /** + * Test for {@link HostTest#run(ITestInvocationListener)}, for test with Junit4 style and + * handling of @Ignored. + */ + public void testRun_junit4style_ignored() throws Exception { + mHostTest.setClassName(Junit4TestClassWithIgnore.class.getName()); + TestIdentifier test1 = + new TestIdentifier(Junit4TestClassWithIgnore.class.getName(), "testPass5"); + TestIdentifier test2 = + new TestIdentifier(Junit4TestClassWithIgnore.class.getName(), "testPass6"); + mListener.testRunStarted((String) EasyMock.anyObject(), EasyMock.eq(2)); + mListener.testStarted(EasyMock.eq(test1)); + mListener.testEnded(EasyMock.eq(test1), (Map<String, String>) EasyMock.anyObject()); + mListener.testStarted(EasyMock.eq(test2)); + mListener.testIgnored(EasyMock.eq(test2)); + mListener.testEnded(EasyMock.eq(test2), (Map<String, String>) EasyMock.anyObject()); + mListener.testRunEnded(EasyMock.anyLong(), (Map<String, String>) EasyMock.anyObject()); + EasyMock.replay(mListener); + mHostTest.run(mListener); + EasyMock.verify(mListener); + } + + /** * Test for {@link HostTest#run(ITestInvocationListener)}, for test with Junit4 style and with * method filtering. Only run the expected method. */ |