Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(Parameterized.class)
- @Parameters
- @RunWith(Parameterized.class)
- public class ParameterizedTest {
- private File file;
- public ParameterizedTest(File file) {
- this.file = file;
- }
- @Test
- public void test1() throws Exception { }
- @Test
- public void test2() throws Exception { }
- @Parameters
- public static Collection<Object[]> data() {
- // load the files as you want
- Object[] fileArg1 = new Object[] { new File("path1") };
- Object[] fileArg2 = new Object[] { new File("path2") };
- Collection<Object[]> data = new ArrayList<Object[]>();
- data.add(fileArg1);
- data.add(fileArg2);
- return data;
- }
- }
- public class XTest extends TestCase {
- public File file;
- public XTest(File file) {
- super(file.toString());
- this.file = file;
- }
- public void testX() {
- fail("Failed: " + file);
- }
- }
- public class XTestSuite extends TestSuite {
- public static Test suite() {
- TestSuite suite = new TestSuite("XTestSuite");
- File[] files = new File(".").listFiles();
- for (File file : files) {
- suite.addTest(new XTest(file));
- }
- return suite;
- }
- }
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.junit.runners.Parameterized;
- import org.junit.runners.Parameterized.Parameters;
- @RunWith(Parameterized.class)
- public class TestY {
- @Parameters
- public static Collection<Object[]> getFiles() {
- Collection<Object[]> params = new ArrayList<Object[]>();
- for (File f : new File(".").listFiles()) {
- Object[] arr = new Object[] { f };
- params.add(arr);
- }
- return params;
- }
- private File file;
- public TestY(File file) {
- this.file = file;
- }
- @Test
- public void testY() {
- fail(file.toString());
- }
- }
- [RowTest]
- [Row( 1000, 7, 142.85715)]
- [Row( 1000, 0.00001, 100000000)]
- [Row(4195835, 3145729, 1.3338196)]
- public void DivisionTest(double numerator, double denominator, double result)
- {
- Assert.AreEqual(result, numerator / denominator, 0.00001);
- }
- public void testAllFiles()
- {
- string sCollectingParam = "";
- // loop for each file
- // if test condition fails (can't use junit assert as that would bail out on first failure)
- // add to sCollectingParam with a descriptive log with filename
- assertEquals("Some files failed the test", "", sCollectingParam);
- }
Add Comment
Please, Sign In to add comment