Java Code Examples for org.junit.jupiter.api.extension.ExtensionContext#getRequiredTestMethod()
The following examples show how to use
org.junit.jupiter.api.extension.ExtensionContext#getRequiredTestMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringExtension.java From java-technology-stack with MIT License | 7 votes |
/** * Delegates to {@link TestContextManager#beforeTestExecution}. */ @Override public void beforeTestExecution(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); getTestContextManager(context).beforeTestExecution(testInstance, testMethod); }
Example 2
Source File: SpringExtension.java From spring-analysis-note with MIT License | 6 votes |
/** * Delegates to {@link TestContextManager#afterTestMethod}. */ @Override public void afterEach(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); Throwable testException = context.getExecutionException().orElse(null); getTestContextManager(context).afterTestMethod(testInstance, testMethod, testException); }
Example 3
Source File: UseDataProviderInvocationContextProvider.java From junit-dataprovider with Apache License 2.0 | 6 votes |
@Override protected Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext context, TEST_ANNOTATION annotation) { Method testMethod = context.getRequiredTestMethod(); DataProviderResolverContext dataProviderResolverContext = getDataProviderResolverContext(context, annotation); List<Method> dataProviderMethods = findDataProviderMethods(dataProviderResolverContext); checkArgument(dataProviderMethods.size() > 0, String.format("Could not find a dataprovider for test '%s' using resolvers '%s'.", testMethod, dataProviderResolverContext.getResolverClasses())); return dataProviderMethods.stream().flatMap(dpm -> { DATAPROVIDER_ANNOTATION dataProviderAnnotation = dpm.getAnnotation(dataProviderAnnotationClass); boolean cacheDataProviderResult = cacheDataProviderResult(dataProviderAnnotation); Object data = invokeDataProviderMethodToRetrieveData(dpm, cacheDataProviderResult, context); return convertData(testMethod, data, getConverterContext(dataProviderAnnotation)) .map(d -> (TestTemplateInvocationContext) new DataProviderInvocationContext(testMethod, d, getDisplayNameContext(dataProviderAnnotation))); }); }
Example 4
Source File: TimingExtension.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 5 votes |
@Override public void afterTestExecution(ExtensionContext context) throws Exception { Method testMethod = context.getRequiredTestMethod(); long start = getStore(context).remove(testMethod, long.class); long duration = System.currentTimeMillis() - start; log.info("Method {} took {} ms", testMethod.getName(), duration); }
Example 5
Source File: CustomResolverUseDataProviderArgumentProvider.java From junit-dataprovider with Apache License 2.0 | 5 votes |
@Override protected DataProviderResolverContext getDataProviderResolverContext(ExtensionContext extensionContext, CustomResolverUseDataProvider annotation) { return new DataProviderResolverContext(extensionContext.getRequiredTestMethod(), asList(annotation.resolver()), annotation.resolveStrategy(), generateLocations(extensionContext.getRequiredTestClass(), annotation.location()), DataProvider.class, annotation.value()); }
Example 6
Source File: AbstractDataProviderInvocationContextProvider.java From junit-dataprovider with Apache License 2.0 | 5 votes |
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { Method testMethod = context.getRequiredTestMethod(); return AnnotationUtils.findAnnotation(testMethod, testAnnotationClass) .map(annotation -> provideInvocationContexts(context, annotation)) .orElseThrow(() -> new ExtensionConfigurationException(String.format( "Could not find annotation '%s' on test method '%s'.", testAnnotationClass, testMethod))); }
Example 7
Source File: DbUnitInitializerRule.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override public void beforeEach(ExtensionContext extensionContext) { Method requiredTestMethod = extensionContext.getRequiredTestMethod(); if (requiredTestMethod.getAnnotation(DataSet.class) != null) { setUp(extensionContext.getRequiredTestClass()); } }
Example 8
Source File: ResourceSetGlobalCompilationUnitExtension.java From sarl with Apache License 2.0 | 5 votes |
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { final ResourceSetGlobalCompilationContext ctx = getOrCreateCompilationContext(context); final Method meth = context.getRequiredTestMethod(); ctx.setCurrentMethod(meth.getName()); return Stream.of(new DynamicContext(meth.getName())); }
Example 9
Source File: SpringExtension.java From spring-test-junit5 with Apache License 2.0 | 5 votes |
/** * Delegates to {@link TestContextManager#beforeTestMethod}. */ @Override public void beforeEach(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); getTestContextManager(context).beforeTestMethod(testInstance, testMethod); }
Example 10
Source File: ParallelLoadExtension.java From zerocode with Apache License 2.0 | 5 votes |
@Override public void beforeEach(ExtensionContext extensionContext) throws Exception { Method testMethod = extensionContext.getRequiredTestMethod(); Class<?> testClass = extensionContext.getRequiredTestClass(); String loadPropertiesFile = validateAndGetLoadPropertiesFile(testClass, testMethod); JupiterLoadProcessor loadProcessor = new JupiterLoadProcessor(loadPropertiesFile); //------------------------------------------- // On/Off Extent-Report switch //------------------------------------------- // Load the key 'chart.dashboard.generation' // from 'loadPropertiesFile' //------------------------------------------- boolean chartAndDashBoardGenerationEnabled = false; TestMapping[] testMappingArray = testMethod.getAnnotationsByType(TestMapping.class); Arrays.stream(testMappingArray).forEach(thisMapping -> { loadProcessor.addJupiterTest(thisMapping.testClass(), thisMapping.testMethod()); }); boolean hasFailed = loadProcessor.processMultiLoad(); reportGenerator.generateCsvReport(); if (chartAndDashBoardGenerationEnabled) { reportGenerator.generateExtentReport(); } if (hasFailed) { failTest(testMethod, testClass); } else { LOGGER.info("\nAll Passed \uD83D\uDC3C. \nSee the granular 'csv report' for individual test statistics."); } }
Example 11
Source File: RetryableTestExtension.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private RetryExecutor retryExecutor(ExtensionContext context) { Method method = context.getRequiredTestMethod(); ExtensionContext templateContext = context.getParent() .orElseThrow(() -> new IllegalStateException( "Extension context \"" + context + "\" should have a parent context.")); int maxRetries = maxRetries(context); return templateContext.getStore(NAMESPACE).getOrComputeIfAbsent(method.toString(), __ -> new RetryExecutor(maxRetries), RetryExecutor.class); }
Example 12
Source File: SpringExtension.java From spring-analysis-note with MIT License | 5 votes |
/** * Delegates to {@link TestContextManager#beforeTestMethod}. */ @Override public void beforeEach(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); getTestContextManager(context).beforeTestMethod(testInstance, testMethod); }
Example 13
Source File: TimingExtension.java From mastering-junit5 with Apache License 2.0 | 5 votes |
@Override public void afterTestExecution(ExtensionContext context) throws Exception { Method testMethod = context.getRequiredTestMethod(); long start = getStore(context).remove(testMethod, long.class); long duration = System.currentTimeMillis() - start; log.info("Method {} took {} ms", testMethod.getName(), duration); }
Example 14
Source File: SpringExtension.java From java-technology-stack with MIT License | 5 votes |
/** * Delegates to {@link TestContextManager#afterTestMethod}. */ @Override public void afterEach(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); Throwable testException = context.getExecutionException().orElse(null); getTestContextManager(context).afterTestMethod(testInstance, testMethod, testException); }
Example 15
Source File: AbstractUseDataProviderArgumentProvider.java From junit-dataprovider with Apache License 2.0 | 5 votes |
@Override public Stream<? extends Arguments> provideArguments(ExtensionContext context) { Method testMethod = context.getRequiredTestMethod(); DataProviderResolverContext resolverContext = getDataProviderResolverContext(context, sourceAnnotation); return findDataProviderMethods(resolverContext).stream().flatMap(dpm -> { DATAPROVIDER_ANNOTATION dataProviderAnnotation = dpm.getAnnotation(dataProviderAnnotationClass); boolean cacheDataProviderResult = cacheDataProviderResult(dataProviderAnnotation); Object data = invokeDataProviderMethodToRetrieveData(dpm, cacheDataProviderResult, context); return convertData(testMethod, data, getConverterContext(dataProviderAnnotation)); }); }
Example 16
Source File: CustomResolverDataProviderTestExtension.java From junit-dataprovider with Apache License 2.0 | 5 votes |
@Override protected DataProviderResolverContext getDataProviderResolverContext(ExtensionContext extensionContext, CustomResolverDataProviderTest annotation) { return new DataProviderResolverContext(extensionContext.getRequiredTestMethod(), asList(annotation.resolver()), annotation.resolveStrategy(), generateLocations(extensionContext.getRequiredTestClass(), annotation.location()), DataProvider.class, annotation.value()); }
Example 17
Source File: DataProviderInvocationContextProvider.java From junit-dataprovider with Apache License 2.0 | 5 votes |
@Override protected Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext extensionContext, TEST_ANNOTATION testAnnotation) { Method testMethod = extensionContext.getRequiredTestMethod(); return convertData(testMethod, getData(testAnnotation), getConverterContext(testAnnotation)) .map(d -> new DataProviderInvocationContext(testMethod, d, getDisplayNameContext(testAnnotation))); }
Example 18
Source File: SpringExtension.java From spring-analysis-note with MIT License | 5 votes |
/** * Delegates to {@link TestContextManager#beforeTestExecution}. */ @Override public void beforeTestExecution(ExtensionContext context) throws Exception { Object testInstance = context.getRequiredTestInstance(); Method testMethod = context.getRequiredTestMethod(); getTestContextManager(context).beforeTestExecution(testInstance, testMethod); }
Example 19
Source File: AbstractStringDataProviderArgumentProvider.java From junit-dataprovider with Apache License 2.0 | 4 votes |
@Override public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { Method testMethod = extensionContext.getRequiredTestMethod(); return convertData(testMethod, getData(sourceAnnotation), getConverterContext(sourceAnnotation)); }
Example 20
Source File: PerfConfigContext.java From junitperf with Apache License 2.0 | 4 votes |
public PerfConfigContext(ExtensionContext context) { this.method = context.getRequiredTestMethod(); this.perfConfig = method.getAnnotation(JunitPerfConfig.class); this.perfRequire = method.getAnnotation(JunitPerfRequire.class); }