Consistently supply test name to @Parameters

This commit is contained in:
Sam Brannen
2015-05-05 14:05:25 +02:00
parent 77937c5b02
commit 572cbb0821
10 changed files with 91 additions and 94 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.*;
@@ -66,24 +67,24 @@ public class FailingBeforeAndAfterMethodsJUnitTests {
protected final Class<?> clazz;
public FailingBeforeAndAfterMethodsJUnitTests(final Class<?> clazz) {
this.clazz = clazz;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][] {//
//
{ AlwaysFailingBeforeTestClassTestCase.class },//
{ AlwaysFailingAfterTestClassTestCase.class },//
{ AlwaysFailingPrepareTestInstanceTestCase.class },//
{ AlwaysFailingBeforeTestMethodTestCase.class },//
{ AlwaysFailingAfterTestMethodTestCase.class },//
{ FailingBeforeTransactionTestCase.class },//
{ FailingAfterTransactionTestCase.class } //
{ AlwaysFailingBeforeTestClassTestCase.class.getSimpleName() },//
{ AlwaysFailingAfterTestClassTestCase.class.getSimpleName() },//
{ AlwaysFailingPrepareTestInstanceTestCase.class.getSimpleName() },//
{ AlwaysFailingBeforeTestMethodTestCase.class.getSimpleName() },//
{ AlwaysFailingAfterTestMethodTestCase.class.getSimpleName() },//
{ FailingBeforeTransactionTestCase.class.getSimpleName() },//
{ FailingAfterTransactionTestCase.class.getSimpleName() } //
});
}
public FailingBeforeAndAfterMethodsJUnitTests(String testClassName) throws Exception {
this.clazz = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
}
@Test
public void runTestAndAssertCounters() throws Exception {
final TrackingRunListener listener = new TrackingRunListener();

View File

@@ -34,6 +34,7 @@ import org.springframework.test.context.testng.AbstractTransactionalTestNGSpring
import org.springframework.test.context.testng.TrackingTestNGTestListener;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.util.ClassUtils;
import org.testng.TestNG;
@@ -73,30 +74,29 @@ public class FailingBeforeAndAfterMethodsTestNGTests {
protected final int expectedFailedConfigurationsCount;
public FailingBeforeAndAfterMethodsTestNGTests(final Class<?> clazz, final int expectedTestStartCount,
final int expectedTestSuccessCount, final int expectedFailureCount,
final int expectedFailedConfigurationsCount) {
this.clazz = clazz;
@Parameters(name = "{0}")
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][] {//
//
{ AlwaysFailingBeforeTestClassTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestClassTestCase.class.getSimpleName(), 1, 1, 0, 1 },//
{ AlwaysFailingPrepareTestInstanceTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingBeforeTestMethodTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestMethodTestCase.class.getSimpleName(), 1, 1, 0, 1 },//
{ FailingBeforeTransactionTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ FailingAfterTransactionTestCase.class.getSimpleName(), 1, 1, 0, 1 } //
});
}
public FailingBeforeAndAfterMethodsTestNGTests(String testClassName, int expectedTestStartCount,
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) throws Exception {
this.clazz = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
this.expectedTestStartCount = expectedTestStartCount;
this.expectedTestSuccessCount = expectedTestSuccessCount;
this.expectedFailureCount = expectedFailureCount;
this.expectedFailedConfigurationsCount = expectedFailedConfigurationsCount;
}
@Parameters
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][] {//
//
{ AlwaysFailingBeforeTestClassTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestClassTestCase.class, 1, 1, 0, 1 },//
{ AlwaysFailingPrepareTestInstanceTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingBeforeTestMethodTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestMethodTestCase.class, 1, 1, 0, 1 },//
{ FailingBeforeTransactionTestCase.class, 1, 0, 0, 1 },//
{ FailingAfterTransactionTestCase.class, 1, 1, 0, 1 } //
});
}
@Test
public void runTestAndAssertCounters() throws Exception {
final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,26 +59,22 @@ public class ParameterizedDependencyInjectionTests {
private static final List<Employee> employees = new ArrayList<Employee>();
private final TestContextManager testContextManager = new TestContextManager(getClass());
@Autowired
private ApplicationContext applicationContext;
@Autowired
private Pet pet;
private final String employeeBeanName;
private final String employeeName;
@Parameter(0)
public String employeeBeanName;
private final TestContextManager testContextManager;
@Parameter(1)
public String employeeName;
public ParameterizedDependencyInjectionTests(final String employeeBeanName, final String employeeName)
throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.employeeBeanName = employeeBeanName;
this.employeeName = employeeName;
}
@Parameters
@Parameters(name = "bean [{0}], employee [{1}]")
public static Collection<String[]> employeeData() {
return Arrays.asList(new String[][] { { "employee1", "John Smith" }, { "employee2", "Jane Smith" } });
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.*;
@@ -52,7 +53,7 @@ public class RepeatedSpringRunnerTests {
private static final AtomicInteger invocationCount = new AtomicInteger();
private final Class<? extends AbstractRepeatedTestCase> testClass;
private final Class<?> testClass;
private final int expectedFailureCount;
@@ -63,28 +64,28 @@ public class RepeatedSpringRunnerTests {
private final int expectedInvocationCount;
public RepeatedSpringRunnerTests(Class<? extends AbstractRepeatedTestCase> testClass, int expectedFailureCount,
int expectedTestStartedCount, int expectedTestFinishedCount, int expectedInvocationCount) {
this.testClass = testClass;
@Parameters(name = "{0}")
public static Collection<Object[]> repetitionData() {
return Arrays.asList(new Object[][] {//
//
{ NonAnnotatedRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ DefaultRepeatValueRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ NegativeRepeatValueRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ RepeatedFiveTimesRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 5 },//
{ RepeatedFiveTimesViaMetaAnnotationRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 5 },//
{ TimedRepeatedTestCase.class.getSimpleName(), 3, 4, 4, (5 + 1 + 4 + 10) } //
});
}
public RepeatedSpringRunnerTests(String testClassName, int expectedFailureCount,
int expectedTestStartedCount, int expectedTestFinishedCount, int expectedInvocationCount) throws Exception {
this.testClass = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
this.expectedFailureCount = expectedFailureCount;
this.expectedTestStartedCount = expectedTestStartedCount;
this.expectedTestFinishedCount = expectedTestFinishedCount;
this.expectedInvocationCount = expectedInvocationCount;
}
@Parameters
public static Collection<Object[]> repetitionData() {
return Arrays.asList(new Object[][] {//
//
{ NonAnnotatedRepeatedTestCase.class, 0, 1, 1, 1 },//
{ DefaultRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },//
{ NegativeRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },//
{ RepeatedFiveTimesRepeatedTestCase.class, 0, 1, 1, 5 },//
{ RepeatedFiveTimesViaMetaAnnotationRepeatedTestCase.class, 0, 1, 1, 5 },//
{ TimedRepeatedTestCase.class, 3, 4, 4, (5 + 1 + 4 + 10) } //
});
}
@Test
public void assertRepetitions() throws Exception {
TrackingRunListener listener = new TrackingRunListener();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextLoader;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import static org.junit.Assert.*;
@@ -55,12 +55,7 @@ public class GenericXmlContextLoaderResourceLocationsTests {
protected final String[] expectedLocations;
public GenericXmlContextLoaderResourceLocationsTests(final Class<?> testClass, final String[] expectedLocations) {
this.testClass = testClass;
this.expectedLocations = expectedLocations;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> contextConfigurationLocationsData() {
@ContextConfiguration
class ClasspathNonExistentDefaultLocationsTestCase {
@@ -93,25 +88,25 @@ public class GenericXmlContextLoaderResourceLocationsTests {
return Arrays.asList(new Object[][] {
{ ClasspathNonExistentDefaultLocationsTestCase.class, new String[] {} },
{ ClasspathNonExistentDefaultLocationsTestCase.class.getSimpleName(), new String[] {} },
{
ClasspathExistentDefaultLocationsTestCase.class,
ClasspathExistentDefaultLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests$1ClasspathExistentDefaultLocationsTestCase-context.xml" } },
{
ImplicitClasspathLocationsTestCase.class,
ImplicitClasspathLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:/org/springframework/test/context/support/context1.xml",
"classpath:/org/springframework/test/context/support/context2.xml" } },
{ ExplicitClasspathLocationsTestCase.class, new String[] { "classpath:context.xml" } },
{ ExplicitClasspathLocationsTestCase.class.getSimpleName(), new String[] { "classpath:context.xml" } },
{ ExplicitFileLocationsTestCase.class, new String[] { "file:/testing/directory/context.xml" } },
{ ExplicitFileLocationsTestCase.class.getSimpleName(), new String[] { "file:/testing/directory/context.xml" } },
{ ExplicitUrlLocationsTestCase.class, new String[] { "http://example.com/context.xml" } },
{ ExplicitUrlLocationsTestCase.class.getSimpleName(), new String[] { "http://example.com/context.xml" } },
{
ExplicitMixedPathTypesLocationsTestCase.class,
ExplicitMixedPathTypesLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:/org/springframework/test/context/support/context1.xml",
"classpath:context2.xml", "classpath:/context3.xml", "file:/testing/directory/context.xml",
"http://example.com/context.xml" } }
@@ -119,6 +114,11 @@ public class GenericXmlContextLoaderResourceLocationsTests {
});
}
public GenericXmlContextLoaderResourceLocationsTests(final String testClassName, final String[] expectedLocations) throws Exception {
this.testClass = ClassUtils.forName(getClass().getName() + "$1" + testClassName, getClass().getClassLoader());
this.expectedLocations = expectedLocations;
}
@Test
public void assertContextConfigurationLocations() throws Exception {