public class FactoryDataProviderSampleTest {
@Factory(dataProvider = "dp")
public FactoryDataProviderSampleTest(int n) {
super(n);
}
@DataProvider
static public Object[][] dp() {
return new Object[][] {
new Object[] { 41 },
new Object[] { 42 },
};
}
}
--
Regards / Pozdrawiam
Tomek Kaczanowski
2011/4/26 Cédric Beust ♔ <ced...@beust.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To post to this group, send email to testng...@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/testng-users?hl=en.
>
Nice indeed.I've been thinking also on a pattern of test I seem to be writing more and more often lately:@DataProvider(name="something")public Object[][[] provideSomething() {...... process a bunch of data - ie csv, jdbc, or other, finding all "failing data"}@Testpublic void fail(SomeObject dataThatFails fail) {fail("Bad data found " + fail);}
( the test sometimes has some actual tests in it tho )I've thought of maybe doing this as a @Factory that returns instances of an anonymous inner class at times, but thought something like:@Testpublic void testSomeData(IProvidedTest auto) {for (Object each : something ) {auto.callback(new Object[][] { xxx. xxx };}}where IProvidedTest is some form of TestNG generated meta-test, which kinda inverts things. I've not really thought too much on a better way to write it tho.
The other idea I had for tests with a few variations was:@Test(data=[@Data("one", "two", three"),@Data("four", "five", "six")])public void testit(String first, String second, String third) {}
I'm confused by all your ideas except one :-)
Invoking a test method that will always fail? Not sure what the point of that would be(?).
The other idea I had for tests with a few variations was:@Test(data=[@Data("one", "two", three"),@Data("four", "five", "six")])public void testit(String first, String second, String third) {}This would be very limited since Java annotations can only contain constants...
boolean single;
@Parameters({"single"})
public DemoTest(@Optional("true") boolean single) {
this.single = single;
}
@Factory(dataProvider = "createInstances")
public DemoTest(String name) {
....
}
@DataProvider
public Object[][] createInstances() {
if(single) {
return new Object[][] { new Object[] { "single" } };
}
return new Object[][] {
new Object[] { "first" },
new Object[] { "second" },
};
}
The first constructor will only be called to create a temporary object to call the non-static DataProvider.--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/nCGwcAmQSu8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.