本文整理汇总了Java中org.junit.jupiter.api.TestFactory类的典型用法代码示例。如果您正苦于以下问题:Java TestFactory类的具体用法?Java TestFactory怎么用?Java TestFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestFactory类属于org.junit.jupiter.api包,在下文中一共展示了TestFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: streamTest
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> streamTest() {
// Input data
Integer array[] = { 1, 2, 3 };
Iterator<Integer> inputGenerator = Arrays.asList(array).iterator();
// Display names
Function<Integer, String> displayNameGenerator = (
input) -> "Data input:" + input;
// Test executor
ThrowingConsumer<Integer> testExecutor = (input) -> {
System.out.println(input);
assertTrue(input % 2 == 0);
};
// Returns a stream of dynamic tests
return stream(inputGenerator, displayNameGenerator, testExecutor);
}
示例2: dynamicTestsFromStream
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
@Test
@Epic("epic1")
@Epic("epic2")
@Epic("epic3")
@Feature("feature1")
@Feature("feature2")
@Feature("feature3")
@Story("story1")
@Stories({
@Story("story2"),
@Story("story3")
})
@Owner("some-owner")
Stream<DynamicTest> dynamicTestsFromStream() {
return Stream.of("A", "B", "C").map(str -> dynamicTest("test" + str, () -> {
}));
}
示例3: queryTable
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
public Stream<DynamicTest> queryTable() throws SQLException {
List<ChangeKey> changeCaptureTables = new ArrayList<>();
PooledConnection pooledConnection = null;
try {
pooledConnection = JdbcUtils.openPooledConnection(this.config, new ChangeKey(MsSqlTestConstants.DATABASE_NAME, null, null));
MsSqlQueryBuilder queryBuilder = new MsSqlQueryBuilder(pooledConnection.getConnection());
try (PreparedStatement statement = queryBuilder.listChangeTrackingTablesStatement()) {
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String databaseName = resultSet.getString("databaseName");
String schemaName = resultSet.getString("schemaName");
String tableName = resultSet.getString("tableName");
ChangeKey changeKey = new ChangeKey(databaseName, schemaName, tableName);
changeCaptureTables.add(changeKey);
log.trace("Found Change Tracking Enabled Table {}", changeKey);
}
}
}
} finally {
JdbcUtils.closeConnection(pooledConnection);
}
return changeCaptureTables.stream().map(data -> dynamicTest(data.tableName, () -> queryTable(data)));
}
示例4: assertSchema
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
public Stream<DynamicTest> assertSchema() {
List<TestCase> tests = new ArrayList<>();
of(tests, Schema.STRING_SCHEMA, Schema.STRING_SCHEMA, true);
of(tests, Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, false);
of(tests, Schema.BYTES_SCHEMA, Decimal.schema(4), false);
of(tests, null, null, true);
of(tests, Schema.STRING_SCHEMA, null, false);
of(tests, null, Schema.STRING_SCHEMA, false);
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
if (testCase.isEqual) {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
} else {
assertThrows(AssertionFailedError.class, () -> {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
});
}
}));
}
示例5: badData
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> badData() {
List<Schema> schemas = Arrays.asList(
Schema.INT8_SCHEMA,
Schema.INT16_SCHEMA,
Schema.INT32_SCHEMA,
Schema.INT64_SCHEMA,
Schema.FLOAT32_SCHEMA,
Schema.FLOAT64_SCHEMA
);
return schemas.stream().map(schema ->
dynamicTest(schema.type().name(), () -> {
badDataTest(schema);
})
);
}
示例6: badData
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> badData() {
List<Schema> schemas = Arrays.asList(
Schema.INT8_SCHEMA,
Schema.INT16_SCHEMA,
Schema.INT32_SCHEMA,
Schema.INT64_SCHEMA,
Schema.FLOAT32_SCHEMA,
Schema.FLOAT64_SCHEMA
);
return schemas.stream().map(schema ->
dynamicTest(schema.type().name(), () -> {
assertThrows(DataException.class, () -> {
parser.parseString(schema, "asdf");
});
})
);
}
示例7: loadCases
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
@Override
public Stream<DynamicTest> loadCases(String param) throws IOException, URISyntaxException {
return super.loadCases(param)
.map(test -> DynamicTest.dynamicTest(test.getDisplayName(), () -> {
try {
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
// CXF Servlet
ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
cxfServletHolder.setInitParameter("jaxrs.serviceClasses", TestServerResource.class.getName());
servletContextHandler.addServlet(cxfServletHolder, "/*");
server = new Server(4442);
server.setHandler(servletContextHandler);
server.start();
Log.setLog(new StdErrLog());
test.getExecutable().execute();
} finally {
try {
server.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}));
}
示例8: statusEffectsExpireAfterDuration
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
@DisplayName("expires after the duration of ")
Stream<DynamicTest> statusEffectsExpireAfterDuration() {
return IntStream.range(1, 4).mapToObj(duration ->
dynamicTest(duration + " moves of the affected bot", () -> {
Effect effect = createEffectFactoryFor(anyBot(),
duration, NoEffect.class).newInstance();
Bot target = aBot().withStatusEffects(effect).build();
for (int i = 0; i < duration; i++) {
assertFalse(effect.isExpired(), "Effect should not expire after " + i + " moves");
target.applyEffects();
}
assertTrue(effect.isExpired());
}));
}
示例9: testAllPbeTypes
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Iterable<DynamicTest> testAllPbeTypes() throws Exception {
List<DynamicTest> tests = new ArrayList<>();
for (PrivateKey privateKey : privateKeys()) {
for (OpenSslPbeType pbeType : OpenSslPbeType.values()) {
tests.add(dynamicTest("test " + pbeType.name() + "/" + privateKey.getClass().getSimpleName(), () -> {
byte[] encKey = OpenSslPvkUtil.getEncrypted(privateKey, pbeType, PASSWORD).getBytes();
assertEquals(privateKey, OpenSslPvkUtil.loadEncrypted(new ByteArrayInputStream(encKey), PASSWORD));
assertEquals(ENC_OPENSSL_PVK, CryptoFileUtil.detectFileType(new ByteArrayInputStream(encKey)));
}));
}
}
return tests;
}
示例10: TestCase
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Return_All_Permutations() throws NoSuchFieldException {
final Field perm1A = fieldFromPermutation1Class("a");
final Field perm1B = fieldFromPermutation1Class("b");
final Field perm2A = fieldFromPermutation2Class("a");
final Field perm2B = fieldFromPermutation2Class("b");
final Field perm2C = fieldFromPermutation2Class("c");
final TestCase testCase1 = new TestCase(Permutation1.class,
newArrayList(newArrayList(perm1A),
newArrayList(perm1B),
newArrayList(perm1A, perm1B)));
final TestCase testCase2 = new TestCase(Permutation2.class, newArrayList(newArrayList(perm2A),
newArrayList(perm2B),
newArrayList(perm2C),
newArrayList(perm2A, perm2B),
newArrayList(perm2A, perm2C),
newArrayList(perm2B, perm2C),
newArrayList(perm2A, perm2B, perm2C)));
return Stream.of(testCase1, testCase2)
.map(value -> dynamicTest(getDefaultDisplayName(value), Should_Return_All_Permutations(value)));
}
示例11: field
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Throw_Exception_When_Setter_Was_Not_Found() throws NoSuchFieldException {
final Field fieldA = field(Setters.class, "a");
final Field fieldB = field(Setters.class, "b");
final Field fieldC = field(Setters.class, "c");
final Field fieldD = field(Setters.class, "d");
final Field fieldF = field(Setters.class, "f");
final Field fieldG = field(Setters.class, "g");
return Stream.of(fieldA,
fieldB,
fieldC,
fieldD,
fieldF,
fieldG)
.map(value -> dynamicTest(getDefaultDisplayName(value),
Should_Throw_Exception_When_Setter_Was_Not_Found(value)));
}
示例12: dynamicTest
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Change_Array_Value() {
return Stream.of("a_int",
"a_char",
"a_float",
"a_double",
"a_boolean",
"a_byte",
"a_short",
"a_long",
"a_Int",
"a_Char",
"a_Float",
"a_Double",
"a_Boolean",
"a_Byte",
"a_Short",
"a_Long",
"a_object_null",
"a_object",
"a_a")
.map(fieldName -> dynamicTest(getDefaultDisplayName(fieldName),
Should_Change_Array_Value(fieldName)));
}
示例13: CanChangeCase
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Return_True_Or_False_Whether_Can_Change_Or_Not() throws NoSuchFieldException {
return Stream.of(new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_int"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_char"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_float"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_double"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_boolean"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_byte"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_short"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_long"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Int"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Char"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Float"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Double"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Boolean"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Byte"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_object_null"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_object"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_a"), true),
new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a"), false))
.map(value -> dynamicTest(getDefaultDisplayName(value.field.getName()),
Should_Return_True_Or_False_Whether_Can_Change_Or_Not(value)));
}
示例14: AreDifferentCase
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not() {
final Collection<String> collectionABC = new ArrayList<>();
collectionABC.add("A");
collectionABC.add("B");
collectionABC.add("C");
final Collection<String> collectionAB = new ArrayList<>();
collectionAB.add("A");
collectionAB.add("B");
final ArrayList<Object> emptyArrayList = new ArrayList<>();
return Stream.of(new AreDifferentCase(null, null, false),
new AreDifferentCase(emptyArrayList.iterator(), emptyArrayList.iterator(), false),
new AreDifferentCase(collectionABC.iterator(), collectionABC.iterator(), false),
new AreDifferentCase(emptyArrayList.iterator(), null, true),
new AreDifferentCase(null, emptyArrayList.iterator(), true),
new AreDifferentCase(collectionAB.iterator(), collectionABC.iterator(), true))
.map(value -> dynamicTest(getDefaultDisplayName(value.value1 + " " + value.value2),
Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not(value)));
}
示例15: dynamicTest
import org.junit.jupiter.api.TestFactory; //导入依赖的package包/类
@TestFactory
Stream<DynamicTest> Should_Instantiate_Primitive() {
return Stream.of(Integer.class,
Byte.class,
Character.class,
Double.class,
Float.class,
Integer.class,
Long.class,
Short.class,
boolean.class,
byte.class,
char.class,
double.class,
float.class,
int.class,
long.class,
short.class)
.map(value -> dynamicTest(getDefaultDisplayName(value), Should_Instantiate_Primitive(value)));
}