質問

The only framework that comes to my mind for data driven testing is FIT. Am I missing something?

Are there good commercial options ?

Pls. note that I am focussing on low maintenance-costs of tabular test-data by test-designers, preferably done via Excel.

Thanks, Bastl.

役に立ちましたか?

解決

Discussed in Data-driven tests with jUnit

Especially the link to the article http://mrlalonde.blogspot.ca/2012/08/data-driven-tests-with-junit.html answers my question.

Several things to note from my POV:

  • no need to use any other frameworks -- just plain old junit. rock solid concept!
  • in suite() I tend to parse some CSV to create test-cases with input edited by our test-guys in excel.

I like it so much that I take the freedom to paste the relevant code snippet here for self-containedness:

public class DataDrivenTestExample extends TestCase {

private final String expected;
private final String actual;

// must be named suite() for the JUnit Runner to pick it up
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(new DataDrivenTestExample("One", "answer", "answer"));
    suite.addTest(new DataDrivenTestExample("Two", "result", "fail?"));
    suite.addTest(new DataDrivenTestExample("Three", "run-all-tests!", "run-all-tests!"));
    return suite;
}

protected DataDrivenTestExample(String name, String expected, String actual) {
    super(name);
    this.expected = expected;
    this.actual = actual;
}

/**
 * override this; default impl tries to reflectively find methods matching {@link TestCase#getName()}
 */
@Override
protected void runTest() throws Throwable {
    assertEquals(expected, actual);
}
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top