本文整理汇总了Java中org.junit.jupiter.api.extension.ExtendWith类的典型用法代码示例。如果您正苦于以下问题:Java ExtendWith类的具体用法?Java ExtendWith怎么用?Java ExtendWith使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtendWith类属于org.junit.jupiter.api.extension包,在下文中一共展示了ExtendWith类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: willCreateANewTemporaryFileEveryTime
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@RepeatedTest(5)
@ExtendWith(TemporaryFolderExtension.class)
public void willCreateANewTemporaryFileEveryTime(TemporaryFolder temporaryFolder)
throws IOException {
File file = temporaryFolder.createFile("foo.txt");
assertThat(file.exists(), is(true));
if (temporaryFilePaths.isEmpty()) {
temporaryFilePaths.add(file.getAbsolutePath());
} else {
assertThat(
"Received the same value twice, expected each random value to be different!",
temporaryFilePaths,
not(hasItem(file.getAbsolutePath())));
temporaryFilePaths.add(file.getAbsolutePath());
}
}
示例2: willCreateANewTemporaryDirectoryEveryTime
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@RepeatedTest(5)
@ExtendWith(TemporaryFolderExtension.class)
public void willCreateANewTemporaryDirectoryEveryTime(TemporaryFolder temporaryFolder) {
File dir = temporaryFolder.createDirectory("bar");
assertThat(dir.exists(), is(true));
if (temporaryDirectoryPaths.isEmpty()) {
temporaryDirectoryPaths.add(dir.getAbsolutePath());
} else {
assertThat(
"Received the same value twice, expected each random value to be different!",
temporaryDirectoryPaths,
not(hasItem(dir.getAbsolutePath())));
temporaryDirectoryPaths.add(dir.getAbsolutePath());
}
}
示例3: canHandleTheKitchenSink
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@Test
@ExtendWith(TemporaryFolderExtension.class)
@ExpectedException(type = RuntimeException.class, messageIs = "Doh!")
public void canHandleTheKitchenSink(TemporaryFolder temporaryFolder, @Random Long anyLong)
throws IOException {
// randomness
assertThat(anyString, notNullValue());
assertThat(anyLong, notNullValue());
// system property
assertThat(System.getProperty("x"), is("y"));
// temporary folder
File file = temporaryFolder.createFile("foo.txt");
assertThat(file.exists(), is(true));
// expected exception
throw new RuntimeException("Doh!");
}
示例4: testParametersNeedExtraAnnotation
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@Test
@ExtendWith(CustomExtension.class)
@ExplicitParamInjection
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
// Bar should be resolved by another extension
Assertions.assertNotNull(bar);
Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
// Foo should be resolved as usual
Assertions.assertNotNull(foo);
Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
// BeanWithQualifier should be resolved
Assertions.assertNotNull(bean);
Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}
示例5: testParametersNeedExtraAnnotation
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@Test
@ExtendWith(CustomExtension.class)
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
// Bar should be resolved by another extension
Assertions.assertNotNull(bar);
Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
// Foo should be resolved as usual
Assertions.assertNotNull(foo);
Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
// BeanWithQualifier should be resolved
Assertions.assertNotNull(bean);
Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}
示例6: doesNotResolveEveryParameter
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@Test
@ExtendWith(FooBarExtension.class)
void doesNotResolveEveryParameter(String string, String[] fooBar, Injector injector) {
assertThat(string).isEqualTo(TestModule.STRING);
assertThat(fooBar).asList().containsExactly("foo", "bar").inOrder();
assertNull(injector.getExistingBinding(Key.get(String[].class)));
}
示例7: canInjectATemporaryFolderAsAParameter
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@Test
@ExtendWith(TemporaryFolderExtension.class)
public void canInjectATemporaryFolderAsAParameter(TemporaryFolder temporaryFolder)
throws IOException {
File file = temporaryFolder.createFile("foo.txt");
assertThat(file.exists(), is(true));
File dir = temporaryFolder.createDirectory("bar");
assertThat(dir.exists(), is(true));
}
示例8: willInjectANewRandomValueEachTime
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@RepeatedTest(5)
@ExtendWith(RandomBeansExtension.class)
public void willInjectANewRandomValueEachTime(@Random String anyString) {
assertThat(anyString, notNullValue());
if (anyStrings.isEmpty()) {
anyStrings.add(anyString);
} else {
assertThat(
"Received the same value twice, expected each random value to be different!",
anyStrings,
not(hasItem(anyString)));
anyStrings.add(anyString);
}
}
示例9: testDateTimeDirectAnnotation
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(DataProviderExtension.class)
@DataProvider(value = {
"2016-02-19 | 2016 | 02 | 19 | 00 | 00 | 00 | 000 | UTC",
"2016-02-19T20:15:22.629 GMT | 2016 | 02 | 19 | 20 | 15 | 22 | 629 | UTC",
}, splitBy = "\\|", stringConverter = DateTimeAwareStringConverter.class)
// @formatter:off
void testDateTimeDirectAnnotation(Date date, int year, int month, int dayOfMonth, int hourOfDay, int minute,
int second, int millis, String timeZone) {
// Expect:
assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
示例10: testDateTimeDirectMetaAnnotation
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(CustomConverterDataProviderExtension.class)
@CustomConverterDataProvider(value = {
"2016-02-19 | 2016 | 02 | 19 | 00 | 00 | 00 | 000 | UTC",
"2016-02-19T20:15:22.629 GMT | 2016 | 02 | 19 | 20 | 15 | 22 | 629 | UTC",
}, splitBy = "\\|", trimValues = true)
// @formatter:off
void testDateTimeDirectMetaAnnotation(Date date, int year, int month, int dayOfMonth, int hourOfDay, int minute,
int second, int millis, String timeZone) {
// Expect:
assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
示例11: testDateTimeAnnotationAndDataProviderMethod
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(UseDataProviderExtension.class)
@UseDataProvider("dateTimeMetaAnnotationAndDataProviderMethodProvider")
void testDateTimeAnnotationAndDataProviderMethod(Date date, int year, int month, int dayOfMonth, int hourOfDay,
int minute, int second, int millis, String timeZone) {
// Expect:
assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
示例12: testNumber
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(UseDataProviderExtension.class)
@UseDataProvider(resolver = DataProviderStartWithTestMethodNameResolver.class)
void testNumber(Number number) {
// When:
int count = counterOne.incrementAndGet();
// Then:
assertThat(count).isEqualTo(number.intValue());
}
示例13: testTemplate
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
System.out.println(parameter);
}
示例14: test
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@ExtendWith(MyParameterResolver.class)
@Test
public void test(Object parameter) {
System.out.println("My parameter " + parameter);
}
示例15: firstTest
import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@ExtendWith(IgnoreIOExceptionExtension.class)
@Test
public void firstTest() throws IOException {
throw new IOException("IO Exception");
}