1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package android.support.test.internal.runner; 17 18import android.app.Instrumentation; 19import android.os.Bundle; 20import android.support.test.InjectBundle; 21import android.support.test.InjectInstrumentation; 22import android.support.test.filters.RequiresDevice; 23import android.support.test.filters.SdkSuppress; 24import android.support.test.internal.runner.TestRequestBuilder.DeviceBuild; 25import android.test.suitebuilder.annotation.MediumTest; 26import android.test.suitebuilder.annotation.SmallTest; 27import android.test.suitebuilder.annotation.Suppress; 28 29import junit.framework.TestCase; 30 31import org.junit.Assert; 32import org.junit.Test; 33import org.junit.runner.Description; 34import org.junit.runner.JUnitCore; 35import org.junit.runner.Result; 36import org.junit.runner.RunWith; 37import org.junit.runner.notification.RunListener; 38import org.junit.runners.Parameterized; 39import org.mockito.Mock; 40import org.mockito.Mockito; 41import org.mockito.MockitoAnnotations; 42 43import java.io.ByteArrayOutputStream; 44import java.io.PrintStream; 45import java.util.Arrays; 46import java.util.Collection; 47 48/** 49 * Unit tests for {@link TestRequestBuilder}. 50 */ 51public class TestRequestBuilderTest { 52 53 public static class SampleTest { 54 55 @SmallTest 56 @Test 57 public void testSmall() { 58 } 59 60 @Test 61 public void testOther() { 62 } 63 } 64 65 @SmallTest 66 public static class SampleClassSize { 67 68 @Test 69 public void testSmall() { 70 } 71 72 @Test 73 public void testSmallToo() { 74 } 75 } 76 77 public static class SampleNoSize extends TestCase { 78 79 public void testOther() { 80 } 81 82 public void testOther2() { 83 } 84 85 } 86 87 public static class SampleJUnit3Test extends TestCase { 88 89 @SmallTest 90 public void testSmall() { 91 } 92 93 @SmallTest 94 public void testSmall2() { 95 } 96 97 public void testOther() { 98 } 99 } 100 101 @SmallTest 102 public static class SampleJUnit3ClassSize extends TestCase { 103 104 public void testSmall() { 105 } 106 107 public void testSmall2() { 108 } 109 110 } 111 112 @SmallTest 113 public static class SampleOverrideSize extends TestCase { 114 115 public void testSmall() { 116 } 117 118 @MediumTest 119 public void testMedium() { 120 } 121 } 122 123 @SmallTest 124 public static class SampleSameSize extends TestCase { 125 126 @SmallTest 127 public void testSmall() { 128 } 129 130 @MediumTest 131 public void testMedium() { 132 } 133 } 134 135 public static class SampleJUnit3Suppressed extends TestCase { 136 137 public void testRun() { 138 } 139 public void testRun2() { 140 } 141 142 @Suppress 143 public void testSuppressed() { 144 } 145 } 146 147 public static class SampleSizeWithSuppress extends TestCase { 148 149 public void testNoSize() { 150 } 151 152 @SmallTest 153 @Suppress 154 public void testSmallAndSuppressed() { 155 } 156 157 @Suppress 158 public void testSuppressed() { 159 } 160 } 161 162 public static class SampleAllSuppressed extends TestCase { 163 164 @Suppress 165 public void testSuppressed2() { 166 } 167 168 @Suppress 169 public void testSuppressed() { 170 } 171 } 172 173 public static class SampleSizeAndSuppress extends TestCase { 174 175 @MediumTest 176 public void testMedium() { 177 } 178 179 @Suppress 180 public void testSuppressed() { 181 } 182 } 183 184 public static class SampleJUnit3 extends TestCase { 185 public void testFromSuper() { 186 187 } 188 } 189 190 public static class SampleJUnit3SuppressedWithSuper extends SampleJUnit3 { 191 192 public void testRun() { 193 } 194 public void testRun2() { 195 } 196 197 @Suppress 198 public void testSuppressed() { 199 } 200 } 201 202 // test fixtures for super-class annotation processing 203 public static class InheritedAnnnotation extends SampleJUnit3Test { 204 } 205 206 public static class SampleMultipleAnnotation { 207 208 @Test 209 @SmallTest 210 public void testSmallSkipped() { 211 Assert.fail("should not run"); 212 } 213 214 @Test 215 @MediumTest 216 public void testMediumSkipped() { 217 Assert.fail("should not run"); 218 } 219 220 @Test 221 public void testRunThis() { 222 // fail this test too to make it easier to check it was run 223 Assert.fail("should run"); 224 } 225 } 226 227 public static class SampleRequiresDevice { 228 @RequiresDevice 229 @Test 230 public void skipThis() {} 231 232 @Test 233 public void runMe() {} 234 235 @Test 236 public void runMe2() {} 237 } 238 239 public static class SampleSdkSuppress { 240 @SdkSuppress(minSdkVersion=15) 241 @Test 242 public void skipThis() {} 243 244 @SdkSuppress(minSdkVersion=16) 245 @Test 246 public void runMe() {} 247 248 @SdkSuppress(minSdkVersion=17) 249 @Test 250 public void runMe2() {} 251 } 252 253 public static class DollarMethod { 254 255 @Test 256 public void testWith$() { 257 } 258 259 @Test 260 public void testSkipped() { 261 } 262 } 263 264 @RunWith(value = Parameterized.class) 265 public static class ParameterizedTest { 266 267 public ParameterizedTest(int data) { 268 } 269 270 @Parameterized.Parameters 271 public static Collection<Object[]> data() { 272 Object[][] data = new Object[][]{{1}, {2}, {3}}; 273 return Arrays.asList(data); 274 } 275 276 @Test 277 public void testParameterized() { 278 279 } 280 } 281 282 283 @InjectInstrumentation 284 public Instrumentation mInstr; 285 286 @InjectBundle 287 public Bundle mBundle; 288 289 @Mock 290 private DeviceBuild mMockDeviceBuild; 291 292 /** 293 * Test initial condition for size filtering - that all tests run when no filter is attached 294 */ 295 @Test 296 public void testNoSize() { 297 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 298 b.addTestClass(SampleTest.class.getName()); 299 TestRequest request = b.build(mInstr, mBundle); 300 JUnitCore testRunner = new JUnitCore(); 301 Result result = testRunner.run(request.getRequest()); 302 Assert.assertEquals(2, result.getRunCount()); 303 } 304 305 /** 306 * Test that size annotation filtering works 307 */ 308 @Test 309 public void testSize() { 310 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 311 b.addTestClass(SampleTest.class.getName()); 312 b.addTestSizeFilter("small"); 313 TestRequest request = b.build(mInstr, mBundle); 314 JUnitCore testRunner = new JUnitCore(); 315 Result result = testRunner.run(request.getRequest()); 316 Assert.assertEquals(1, result.getRunCount()); 317 } 318 319 /** 320 * Test that size annotation filtering by class works 321 */ 322 @Test 323 public void testSize_class() { 324 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 325 b.addTestClass(SampleTest.class.getName()); 326 b.addTestClass(SampleClassSize.class.getName()); 327 b.addTestSizeFilter("small"); 328 TestRequest request = b.build(mInstr, mBundle); 329 JUnitCore testRunner = new JUnitCore(); 330 Result result = testRunner.run(request.getRequest()); 331 Assert.assertEquals(3, result.getRunCount()); 332 } 333 334 /** 335 * Test case where entire JUnit3 test class has been filtered out 336 */ 337 @Test 338 public void testSize_classFiltered() { 339 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 340 b.addTestClass(SampleTest.class.getName()); 341 b.addTestClass(SampleNoSize.class.getName()); 342 b.addTestSizeFilter("small"); 343 TestRequest request = b.build(mInstr, mBundle); 344 MyRunListener l = new MyRunListener(); 345 JUnitCore testRunner = new JUnitCore(); 346 testRunner.addListener(l); 347 testRunner.run(request.getRequest()); 348 Assert.assertEquals(1, l.mTestCount); 349 } 350 351 private static class MyRunListener extends RunListener { 352 private int mTestCount = -1; 353 354 @Override 355 public void testRunStarted(Description description) throws Exception { 356 mTestCount = description.testCount(); 357 } 358 } 359 360 /** 361 * Test size annotations with JUnit3 test methods 362 */ 363 @Test 364 public void testSize_junit3Method() { 365 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 366 b.addTestClass(SampleJUnit3Test.class.getName()); 367 b.addTestClass(SampleNoSize.class.getName()); 368 b.addTestSizeFilter("small"); 369 TestRequest request = b.build(mInstr, mBundle); 370 JUnitCore testRunner = new JUnitCore(); 371 Result r = testRunner.run(request.getRequest()); 372 Assert.assertEquals(2, r.getRunCount()); 373 } 374 375 /** 376 * Test @Suppress with JUnit3 tests 377 */ 378 @Test 379 public void testSuppress_junit3Method() { 380 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 381 b.addTestClass(SampleJUnit3Suppressed.class.getName()); 382 TestRequest request = b.build(mInstr, mBundle); 383 JUnitCore testRunner = new JUnitCore(); 384 Result r = testRunner.run(request.getRequest()); 385 Assert.assertEquals(2, r.getRunCount()); 386 } 387 388 /** 389 * Test @Suppress in combination with size that filters out all methods 390 */ 391 @Test 392 public void testSuppress_withSize() { 393 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 394 b.addTestClass(SampleJUnit3Suppressed.class.getName()); 395 b.addTestClass(SampleJUnit3Test.class.getName()); 396 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 397 TestRequest request = b.build(mInstr, mBundle); 398 JUnitCore testRunner = new JUnitCore(); 399 MyRunListener l = new MyRunListener(); 400 testRunner.addListener(l); 401 Result r = testRunner.run(request.getRequest()); 402 Assert.assertEquals(2, r.getRunCount()); 403 Assert.assertEquals(2, l.mTestCount); 404 } 405 406 /** 407 * Test @Suppress in combination with size that filters out all methods, with super class. 408 */ 409 @Test 410 public void testSuppress_withSizeAndSuper() { 411 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 412 b.addTestClass(SampleJUnit3SuppressedWithSuper.class.getName()); 413 b.addTestClass(SampleJUnit3Test.class.getName()); 414 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 415 TestRequest request = b.build(mInstr, mBundle); 416 JUnitCore testRunner = new JUnitCore(); 417 MyRunListener l = new MyRunListener(); 418 testRunner.addListener(l); 419 Result r = testRunner.run(request.getRequest()); 420 Assert.assertEquals(2, r.getRunCount()); 421 Assert.assertEquals(2, l.mTestCount); 422 } 423 424 /** 425 * Test @Suppress when all methods have been filtered 426 */ 427 @Test 428 public void testSuppress_all() { 429 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 430 b.addTestClass(SampleAllSuppressed.class.getName()); 431 b.addTestClass(SampleJUnit3Suppressed.class.getName()); 432 TestRequest request = b.build(mInstr, mBundle); 433 JUnitCore testRunner = new JUnitCore(); 434 MyRunListener l = new MyRunListener(); 435 testRunner.addListener(l); 436 Result r = testRunner.run(request.getRequest()); 437 Assert.assertEquals(2, r.getRunCount()); 438 Assert.assertEquals(2, l.mTestCount); 439 } 440 441 /** 442 * Test case where all methods are filtered out by combination of @Suppress and size when all 443 * methods have been filtered. 444 */ 445 @Test 446 public void testSizeAndSuppress() { 447 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 448 b.addTestClass(SampleSizeAndSuppress.class.getName()); 449 b.addTestClass(SampleJUnit3Test.class.getName()); 450 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 451 TestRequest request = b.build(mInstr, mBundle); 452 JUnitCore testRunner = new JUnitCore(); 453 MyRunListener l = new MyRunListener(); 454 testRunner.addListener(l); 455 Result r = testRunner.run(request.getRequest()); 456 Assert.assertEquals(2, r.getRunCount()); 457 Assert.assertEquals(2, l.mTestCount); 458 } 459 460 /** 461 * Test case where method has both a size annotation and suppress annotation. Expect suppress 462 * to overrule the size. 463 */ 464 @Test 465 public void testSizeWithSuppress() { 466 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 467 b.addTestClass(SampleSizeWithSuppress.class.getName()); 468 b.addTestClass(SampleJUnit3Test.class.getName()); 469 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 470 TestRequest request = b.build(mInstr, mBundle); 471 JUnitCore testRunner = new JUnitCore(); 472 MyRunListener l = new MyRunListener(); 473 testRunner.addListener(l); 474 Result r = testRunner.run(request.getRequest()); 475 Assert.assertEquals(2, r.getRunCount()); 476 Assert.assertEquals(2, l.mTestCount); 477 } 478 479 /** 480 * Test that annotation filtering by class works 481 */ 482 @Test 483 public void testAddAnnotationInclusionFilter() { 484 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 485 b.addAnnotationInclusionFilter(SmallTest.class.getName()); 486 b.addTestClass(SampleTest.class.getName()); 487 b.addTestClass(SampleClassSize.class.getName()); 488 TestRequest request = b.build(mInstr, mBundle); 489 JUnitCore testRunner = new JUnitCore(); 490 Result result = testRunner.run(request.getRequest()); 491 Assert.assertEquals(3, result.getRunCount()); 492 } 493 494 /** 495 * Test that annotation filtering by class works 496 */ 497 @Test 498 public void testAddAnnotationExclusionFilter() { 499 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 500 b.addAnnotationExclusionFilter(SmallTest.class.getName()); 501 b.addTestClass(SampleTest.class.getName()); 502 b.addTestClass(SampleClassSize.class.getName()); 503 TestRequest request = b.build(mInstr, mBundle); 504 JUnitCore testRunner = new JUnitCore(); 505 Result result = testRunner.run(request.getRequest()); 506 Assert.assertEquals(1, result.getRunCount()); 507 } 508 509 /** 510 * Test that annotation filtering by class works when methods are from superclass. 511 * 512 * TODO: add a similiar test to upstream junit. 513 */ 514 @Test 515 public void testAddAnnotationInclusionFilter_super() { 516 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 517 b.addAnnotationInclusionFilter(SmallTest.class.getName()); 518 b.addTestClass(InheritedAnnnotation.class.getName()); 519 TestRequest request = b.build(mInstr, mBundle); 520 JUnitCore testRunner = new JUnitCore(); 521 Result result = testRunner.run(request.getRequest()); 522 Assert.assertEquals(2, result.getRunCount()); 523 } 524 525 /** 526 * Test that a method size annotation overrides a class size annotation. 527 */ 528 @Test 529 public void testTestSizeFilter_override() { 530 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 531 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 532 b.addTestClass(SampleOverrideSize.class.getName()); 533 TestRequest request = b.build(mInstr, mBundle); 534 JUnitCore testRunner = new JUnitCore(); 535 Result result = testRunner.run(request.getRequest()); 536 Assert.assertEquals(1, result.getRunCount()); 537 538 b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 539 b.addTestSizeFilter(TestRequestBuilder.MEDIUM_SIZE); 540 b.addTestClass(SampleOverrideSize.class.getName()); 541 request = b.build(mInstr, mBundle); 542 testRunner = new JUnitCore(); 543 result = testRunner.run(request.getRequest()); 544 Assert.assertEquals(1, result.getRunCount()); 545 } 546 547 /** 548 * Test that a method size annotation of same type as class level annotation is correctly 549 * filtered. 550 */ 551 @Test 552 public void testTestSizeFilter_sameAnnotation() { 553 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 554 b.addTestSizeFilter(TestRequestBuilder.SMALL_SIZE); 555 b.addTestClass(SampleSameSize.class.getName()); 556 TestRequest request = b.build(mInstr, mBundle); 557 JUnitCore testRunner = new JUnitCore(); 558 Result result = testRunner.run(request.getRequest()); 559 Assert.assertEquals(1, result.getRunCount()); 560 } 561 562 /** 563 * Test provided multiple annotations to exclude. 564 */ 565 @Test 566 public void testTestSizeFilter_multipleNotAnnotation() { 567 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 568 b.addAnnotationExclusionFilter(SmallTest.class.getName()); 569 b.addAnnotationExclusionFilter(MediumTest.class.getName()); 570 b.addTestClass(SampleMultipleAnnotation.class.getName()); 571 TestRequest request = b.build(mInstr, mBundle); 572 JUnitCore testRunner = new JUnitCore(); 573 Result result = testRunner.run(request.getRequest()); 574 // expect 1 test that failed 575 Assert.assertEquals(1, result.getRunCount()); 576 Assert.assertEquals("testRunThis", 577 result.getFailures().get(0).getDescription().getMethodName()); 578 } 579 580 /** 581 * Test the sharding filter. 582 */ 583 @Test 584 public void testShardingFilter() { 585 JUnitCore testRunner = new JUnitCore(); 586 587 TestRequestBuilder[] builders = new TestRequestBuilder[5]; 588 Result[] results = new Result[4]; 589 int totalRun = 0; 590 // The last iteration through the loop doesn't add a ShardingFilter - it runs all the 591 // tests to establish a baseline for the total number that should have been run. 592 for (int i = 0; i < 5; i++) { 593 TestRequestBuilder b = new TestRequestBuilder(new PrintStream( 594 new ByteArrayOutputStream())); 595 if (i < 4) { 596 b.addShardingFilter(4, i); 597 } 598 builders[i] = b; 599 b.addTestClass(SampleTest.class.getName()); 600 b.addTestClass(SampleNoSize.class.getName()); 601 b.addTestClass(SampleClassSize.class.getName()); 602 b.addTestClass(SampleJUnit3Test.class.getName()); 603 b.addTestClass(SampleOverrideSize.class.getName()); 604 b.addTestClass(SampleJUnit3ClassSize.class.getName()); 605 b.addTestClass(SampleMultipleAnnotation.class.getName()); 606 TestRequest request = b.build(mInstr, mBundle); 607 Result result = testRunner.run(request.getRequest()); 608 if (i == 4) { 609 Assert.assertEquals(result.getRunCount(), totalRun); 610 } else { 611 totalRun += result.getRunCount(); 612 results[i] = result; 613 } 614 } 615 for (int i = 0; i < 4; i++) { 616 // Theoretically everything could collide into one shard, but, we'll trust that 617 // the implementation of hashCode() is random enough to avoid that. 618 Assert.assertTrue(results[i].getRunCount() < totalRun); 619 } 620 } 621 622 /** 623 * Verify that filtering out all tests is not treated as an error 624 */ 625 @Test 626 public void testNoTests() { 627 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 628 b.addTestClass(SampleTest.class.getName()); 629 b.addTestSizeFilter("medium"); 630 TestRequest request = b.build(mInstr, mBundle); 631 JUnitCore testRunner = new JUnitCore(); 632 Result result = testRunner.run(request.getRequest()); 633 Assert.assertEquals(0, result.getRunCount()); 634 } 635 636 /** 637 * Test that {@link SdkSuppress} filters tests as appropriate 638 */ 639 @Test 640 public void testSdkSuppress() { 641 MockitoAnnotations.initMocks(this); 642 TestRequestBuilder b = new TestRequestBuilder(mMockDeviceBuild, 643 new PrintStream(new ByteArrayOutputStream())); 644 Mockito.when(mMockDeviceBuild.getSdkVersionInt()).thenReturn(16); 645 b.addTestClass(SampleSdkSuppress.class.getName()); 646 TestRequest request = b.build(mInstr, mBundle); 647 JUnitCore testRunner = new JUnitCore(); 648 Result result = testRunner.run(request.getRequest()); 649 Assert.assertEquals(2, result.getRunCount()); 650 } 651 652 /** 653 * Test that {@link RequiresDevice} filters tests as appropriate 654 */ 655 @Test 656 public void testRequiresDevice() { 657 MockitoAnnotations.initMocks(this); 658 TestRequestBuilder b = new TestRequestBuilder(mMockDeviceBuild, 659 new PrintStream(new ByteArrayOutputStream())); 660 Mockito.when(mMockDeviceBuild.getHardware()).thenReturn( 661 TestRequestBuilder.EMULATOR_HARDWARE); 662 b.addTestClass(SampleRequiresDevice.class.getName()); 663 TestRequest request = b.build(mInstr, mBundle); 664 JUnitCore testRunner = new JUnitCore(); 665 Result result = testRunner.run(request.getRequest()); 666 Assert.assertEquals(2, result.getRunCount()); 667 } 668 669 /** 670 * Test method filters with dollar signs are allowed 671 */ 672 @Test 673 public void testMethodFilterWithDollar() { 674 TestRequestBuilder b = new TestRequestBuilder(mMockDeviceBuild, 675 new PrintStream(new ByteArrayOutputStream())); 676 b.addTestMethod(DollarMethod.class.getName(), "testWith$"); 677 TestRequest request = b.build(mInstr, mBundle); 678 JUnitCore testRunner = new JUnitCore(); 679 Result result = testRunner.run(request.getRequest()); 680 Assert.assertEquals(1, result.getRunCount()); 681 } 682 683 /** 684 * Test filtering by two methods in single class 685 */ 686 @Test 687 public void testMultipleMethodsFilter() { 688 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 689 b.addTestMethod(SampleJUnit3Test.class.getName(), "testSmall"); 690 b.addTestMethod(SampleJUnit3Test.class.getName(), "testSmall2"); 691 TestRequest request = b.build(mInstr, mBundle); 692 JUnitCore testRunner = new JUnitCore(); 693 Result result = testRunner.run(request.getRequest()); 694 Assert.assertEquals(2, result.getRunCount()); 695 } 696 697 /** 698 * Test filtering by two methods in separate classes 699 */ 700 @Test 701 public void testTwoMethodsDiffClassFilter() { 702 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 703 b.addTestMethod(SampleJUnit3Test.class.getName(), "testSmall"); 704 b.addTestMethod(SampleTest.class.getName(), "testOther"); 705 TestRequest request = b.build(mInstr, mBundle); 706 JUnitCore testRunner = new JUnitCore(); 707 Result result = testRunner.run(request.getRequest()); 708 Assert.assertEquals(2, result.getRunCount()); 709 } 710 711 /** 712 * Test filtering a parameterized method 713 */ 714 @Test 715 public void testParameterizedMethods() throws Exception { 716 TestRequestBuilder b = new TestRequestBuilder(new PrintStream(new ByteArrayOutputStream())); 717 b.addTestMethod(ParameterizedTest.class.getName(), "testParameterized"); 718 TestRequest request = b.build(mInstr, mBundle); 719 JUnitCore testRunner = new JUnitCore(); 720 Result result = testRunner.run(request.getRequest()); 721 Assert.assertEquals(3, result.getRunCount()); 722 } 723} 724