Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 2.91 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Overloaded Parameterized test runner not working with JUnit4Provider
  2. final JUnit4Provider provider = new JUnit4Provider(params);
  3. provider.invoke(testClass);
  4.        
  5. import org.junit.runner.JUnitCore;
  6.  
  7. public class TestRunner {
  8.  
  9. /**
  10.  * @param args
  11.  */
  12. public static void main(final String[] args) {
  13.     final JUnitCore provider = new JUnitCore();
  14.     provider.addListener(new TestJUnitCore4Listener());
  15.     provider.run(UpdateBackgroundImageParameterizedTests.class);
  16.  
  17. }
  18.  
  19. }
  20.        
  21. import org.junit.runner.Description;
  22. import org.junit.runner.notification.RunListener;
  23.  
  24. public class TestJUnitCore4Listener extends RunListener {
  25.  
  26.     @Override
  27.     public void testFinished(final Description description) throws Exception {
  28.          System.out.println(description.getDisplayName() + " "
  29.             + description.getMethodName());
  30.     }
  31.  
  32. }
  33.        
  34. import static org.junit.Assert.assertTrue;
  35.  
  36. import java.util.Arrays;
  37. import java.util.Collection;
  38.  
  39. import org.junit.Test;
  40. import org.junit.runner.RunWith;
  41. import org.junit.runners.Parameterized.Parameters;
  42.  
  43. @RunWith(LabelledParameterized.class)
  44. public class UpdateBackgroundImageParameterizedTests {
  45.  
  46. // Fields
  47. private final String datum;
  48. private final String expectedResult;
  49.  
  50. /**
  51.  * Constructor is called for every parameter set in generateData()
  52.  *
  53.  * @param datum
  54.  *            input to be used in tests
  55.  * @param expectedResult
  56.  *            output expected by tests
  57.  */
  58. public UpdateBackgroundImageParameterizedTests(final String datum,
  59.         final String expectedResult) {
  60.     super();
  61.     this.datum = datum;
  62.     this.expectedResult = expectedResult;
  63. }
  64.  
  65. /**
  66.  * @return a list of expected inputs and outputs
  67.  */
  68. @Parameters
  69. public static Collection<Object[]> generateData() {
  70.     return Arrays.asList(new Object[][] { { "sunny", "a" }, // 0
  71.             { "cloudy", "a" }, // "a"
  72.             { "rain", "a" }, // 2
  73.             { "heavy snow", "a" }, // 3
  74.             { "occasionally thundery", "a" }, // 4
  75.             { "clear skies", "a" }, // 5
  76.             { "error", "a" } }); // 6
  77. }
  78.  
  79. /**
  80.  * Test updateBackgroundImage using parameter injection for feed Test run
  81.  * for all parameters specified in generateData()
  82.  *
  83.  * @throws Exception
  84.  */
  85. @Test
  86. public void testUpdateBackgroundImage() throws Exception {
  87.     assertTrue(true);
  88. }
  89.  
  90. }
  91.        
  92. testUpdateBackgroundImage[0](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[0]
  93. testUpdateBackgroundImage[1](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[1]
  94. testUpdateBackgroundImage[2](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[2]
  95. testUpdateBackgroundImage[3](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[3]
  96. testUpdateBackgroundImage[4](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[4]
  97. testUpdateBackgroundImage[5](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[5]
  98. testUpdateBackgroundImage[6](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[6]