下面列出了org.testng.annotations.Guice#org.testng.annotations.Factory 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
private static Tuple2<Class<?>, String> getFactoryAnnotationMetaData(final ITestNGMethod testMethod) {
var constructor = testMethod.getConstructorOrMethod().getConstructor();
var method = testMethod.getConstructorOrMethod().getMethod();
var factoryAnnotation = nonNull(method)
? ofNullable(method.getDeclaredAnnotation(Factory.class))
: ofNullable(constructor.getDeclaredAnnotation(Factory.class));
var dataProviderClass = factoryAnnotation
.map(fa -> (Class) fa.dataProviderClass())
.filter(cl -> cl != Object.class)
.orElseGet(() -> testMethod.getConstructorOrMethod().getDeclaringClass());
var dataProviderMethod = factoryAnnotation.map(Factory::dataProvider).orElse("");
return Tuple.of(dataProviderClass, dataProviderMethod);
}
/**
* Creates a test factory for the set of .js source tests.
*
* @return a Object[] of test objects.
* @throws Exception upon failure
*/
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
Locale.setDefault(new Locale(""));
final List<ITest> tests = new ArrayList<>();
final Set<String> orphans = new TreeSet<>();
final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
@Override
public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments);
}
@Override
public void log(final String msg) {
org.testng.Reporter.log(msg, true);
}
};
TestFinder.findAllTests(tests, orphans, testFactory);
if (System.getProperty(TEST_JS_INCLUDES) == null) {
tests.add(new OrphanTestFinder(orphans));
}
return tests.toArray();
}
/**
* Creates a test factory for the set of .js source tests.
*
* @return a Object[] of test objects.
* @throws Exception upon failure
*/
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
Locale.setDefault(new Locale(""));
final List<ITest> tests = new ArrayList<>();
final Set<String> orphans = new TreeSet<>();
final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
@Override
public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments);
}
@Override
public void log(final String msg) {
org.testng.Reporter.log(msg, true);
}
};
TestFinder.findAllTests(tests, orphans, testFactory);
if (System.getProperty(TEST_JS_INCLUDES) == null) {
tests.add(new OrphanTestFinder(orphans));
}
return tests.toArray();
}
/**
* Creates a test factory for the set of .js source tests.
*
* @return a Object[] of test objects.
* @throws Exception upon failure
*/
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
Locale.setDefault(new Locale(""));
final List<ITest> tests = new ArrayList<>();
final Set<String> orphans = new TreeSet<>();
final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
@Override
public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments);
}
@Override
public void log(final String msg) {
org.testng.Reporter.log(msg, true);
}
};
TestFinder.findAllTests(tests, orphans, testFactory);
if (System.getProperty(TEST_JS_INCLUDES) == null) {
tests.add(new OrphanTestFinder(orphans));
}
return tests.toArray();
}
/**
* Creates a test factory for the set of .js source tests.
*
* @return a Object[] of test objects.
* @throws Exception upon failure
*/
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
Locale.setDefault(new Locale(""));
final List<ITest> tests = new ArrayList<>();
final Set<String> orphans = new TreeSet<>();
final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
@Override
public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments);
}
@Override
public void log(final String msg) {
org.testng.Reporter.log(msg, true);
}
};
TestFinder.findAllTests(tests, orphans, testFactory);
if (System.getProperty(TEST_JS_INCLUDES) == null) {
tests.add(new OrphanTestFinder(orphans));
}
return tests.toArray();
}
@Factory(dataProvider = "data")
public HandlerPublisherVerificationTest(int batchSize, int publishInitial, boolean scheduled) {
super(new TestEnvironment(200));
this.batchSize = batchSize;
this.publishInitial = publishInitial;
this.scheduled = scheduled;
}
@Factory(dataProvider = "userModeDataProvider")
public DataTypesTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public InOnlyRequestsServiceTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public ExcelSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "getIncompleteConstructorData")
public IncompleteFactoryTests(final int index) {
// not implemented
}
@Factory(dataProvider = "userModeDataProvider")
public GSpreadSQLDriverSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public CSVSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public SecureDataServiceSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public DTPSampleServiceTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public InMemoryDSSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public FileServiceSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public BatchRequestSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public NestedQuerySampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public ResourcesSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public GSpreadSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public RDBMSSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "userModeDataProvider")
public EventingSampleTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@Factory(dataProvider = "cases")
public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
return new Object[] {
new ConcatTest(scenario, c1, c2, expected)
};
}
@Factory(dataProvider = "dataProvider")
public FactoryOnConstructorTests(final int number, final String v, final Long other) {
this.number = number;
this.v = v;
this.other = other;
}
@Factory(dataProvider = "cases")
public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
return new Object[] {
new ConcatTest(scenario, c1, c2, expected)
};
}
@Factory(dataProvider = "cases")
public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
return new Object[] {
new ConcatTest(scenario, c1, c2, expected)
};
}
@Factory(dataProvider = "clientBuilders")
public AttachmentQueryTest(Builder clientBuilder) {
super(clientBuilder);
}
@Factory
public Object[] allTests() {
return new ReactiveStreamsApiVerification(new DefaultReactiveStreamsFactory()).allTests().toArray();
}
@Factory(dataProvider = "cases")
public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
return new Object[] {
new ConcatTest(scenario, c1, c2, expected)
};
}
@Factory(dataProvider = "cases")
public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
return new Object[] {
new ConcatTest(scenario, c1, c2, expected)
};
}