Skip to content
Browse files

Add a class-based DataProvider

  • Loading branch information...
1 parent 8ed59d1 commit 8ffe0a28e1de3a45b22da78c09bba4366bd4cc0a @jmthibault79 jmthibault79 committed Nov 27, 2013
Showing with 36 additions and 0 deletions.
  1. +36 −0 public/java/test/org/broadinstitute/sting/ExampleToCopyUnitTest.java
View
36 public/java/test/org/broadinstitute/sting/ExampleToCopyUnitTest.java
@@ -105,6 +105,42 @@ public void testMyData(final int start, final int size) {
}
/**
+ * DataProvider example using a class-based data structure
+ */
+ private class MyDataProviderClass extends TestDataProvider {
+ private int start;
+ private int size;
+
+ private MyDataProviderClass(int start, int size) {
+ super(MyDataProviderClass.class);
+ this.start = start;
+ this.size = size;
+ }
+ }
+
+ @DataProvider(name = "MyClassBasedDataProvider")
+ public Object[][] makeMyDataProviderClass() {
+ // this functionality can be adapted to provide input data for whatever you might want in your data
+ for ( final int start : Arrays.asList(1, 10, 100) ) {
+ for ( final int size : Arrays.asList(1, 10, 100, 1000) ) {
+ new MyDataProviderClass(start, size);
+ }
+ }
+
+ return TestDataProvider.getTests(MyDataProviderClass.class);
+ }
+
+ /**
+ * Example testng test using MyClassBasedDataProvider
+ */
+ @Test(dataProvider = "MyClassBasedDataProvider")
+ public void testMyDataProviderClass(MyDataProviderClass testSpec) {
+ // adaptor this code to do whatever testing you want given the arguments start and size
+ Assert.assertTrue(testSpec.start >= 0);
+ Assert.assertTrue(testSpec.size >= 0);
+ }
+
+ /**
* A unit test that creates an artificial read for testing some code that uses reads
*/
@Test()

0 comments on commit 8ffe0a2

Please sign in to comment.
Something went wrong with that request. Please try again.