当前位置: 首页>>代码示例>>Java>>正文


Java ExtendWith类代码示例

本文整理汇总了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());
  }
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:19,代码来源:TemporaryFolderExtensionParameterTest.java

示例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());
  }
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:18,代码来源:TemporaryFolderExtensionParameterTest.java

示例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!");
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:20,代码来源:CompositeExtensionTest.java

示例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());
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:15,代码来源:ExplicitParameterInjectionViaMethodAnnotationTest.java

示例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());
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:14,代码来源:ExplicitParameterInjectionViaClassAnnotationTest.java

示例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)));
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:9,代码来源:GuiceExtensionTest.java

示例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));
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:13,代码来源:TemporaryFolderExtensionParameterTest.java

示例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);
  }
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:16,代码来源:RandomBeansExtensionParameterTest.java

示例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));
}
 
开发者ID:TNG,项目名称:junit-dataprovider,代码行数:13,代码来源:CustomStringConverterAcceptanceTest.java

示例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));
}
 
开发者ID:TNG,项目名称:junit-dataprovider,代码行数:13,代码来源:CustomStringConverterAcceptanceTest.java

示例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));
}
 
开发者ID:TNG,项目名称:junit-dataprovider,代码行数:9,代码来源:CustomStringConverterAcceptanceTest.java

示例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());
}
 
开发者ID:TNG,项目名称:junit-dataprovider,代码行数:11,代码来源:CustomResolverAcceptanceTest.java

示例13: testTemplate

import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
    System.out.println(parameter);
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:6,代码来源:TemplateTest.java

示例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);
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:6,代码来源:DependencyInjectionTest.java

示例15: firstTest

import org.junit.jupiter.api.extension.ExtendWith; //导入依赖的package包/类
@ExtendWith(IgnoreIOExceptionExtension.class)
@Test
public void firstTest() throws IOException {
    throw new IOException("IO Exception");
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:6,代码来源:ExceptionTest.java


注:本文中的org.junit.jupiter.api.extension.ExtendWith类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。