-
Kotlin default parameters: Added support for an alternative way to specify test values in Kotlin:
Examples:
import com.google.testing.junit.testparameterinjector.KotlinTestParameters.testValues
import com.google.testing.junit.testparameterinjector.KotlinTestParameters.namedTestValues
import com.google.testing.junit.testparameterinjector.KotlinTestParameters.testValuesIn
@TestParameter limit: Int = testValues(20, 100),
@TestParameter testCase: AgeCheckTestCase = namedTestValues(
"teenager" to AgeCheckTestCase(17, false),
"young adult" to AgeCheckTestCase(22, true),
),
@TestParameter invalidRequest: Request =
testValuesIn(readRequestsFromFile("invalid_requests.json")),- Minor breaking change: Because of the above, Kotlin test methods with default parameters will no longer work. These defaults would never have been used anyway.
- Minor breaking change: TestParameterInjector will now fail tests that
specify both
@TestParameterson the method and@TestParameteron a parameter.
- Add public method
computeTestMethods(List<FrameworkMethod> methods)toTestParameterInjectorAPI. This can be useful for creating custom extensions ofTestParameterInjector.
-
New Compile-Time Dependency on Kotlin: The library now includes a compile-time dependency on the Kotlin Standard Library (
kotlin-stdlib) and Kotlin Reflection (kotlin-reflect). This is required to properly support Kotlin tests (see the next two changes).If this dependency is causing problems, please let us know by raising an issue. If there is enough need for this, we can justify adding an extra artefact that omits the Kotlin part.
-
Bugfix for Kotlin v2.2.20: Get parameter names via Kotlin reflection because those via Java reflection have changed to include the class.
-
Fix the breaking change in TestParameterInjector v1.19: By getting the parameter names via Kotlin, the breaking change in 1.19 is no longer breaking when directly upgrading to 1.20
-
Breaking change: TestParametersValuesProvider must return at least one value. If your use case requires (sometimes) disabling the test by returning zero values, override
TestParametersValuesProvider.valuesListCanBeEmptyWhichMeansThatTheTestWillBeSkipped().
-
Fix for 2025 Kotlin change that causes the field/parameter of a primary constructor to get its annotation on both the field and the constructor parameter. See https://github.com/google/TestParameterInjector/commit/2f831443f10686087762e55c51bc2d124ffa3bc5
Breaking change: Kotlin test classes that have fields and constructor parameters with overlapping types will cause an error unless the Java
-parametersoption is enabled during compilation. -
Bugfix: Work around a flaky Android-23 crash with annotation proxies. See https://github.com/google/TestParameterInjector/commit/26d981a83d6883d68f5677f3b495682fc35646fd
-
Made some internal JUnit4 methods of
TestParameterInjectorpublic:computeTestMethods()methodBlock()methodInvoker()
These allow any client to combine
TestParameterInjectorwith another JUnit4 runner by manually creating aTestParameterInjectorinstance and calling these methods from the combined JUnit4 runner.
- Added support for parsing
java.time.Durationfrom a string. Example:
@Test
public void myTest(@TestParameter({"1d", "2h20min", "10.5ms"}) Duration duration){...}
- Deprecated
TestParameter.TestParameterValuesProviderin favor of its newer versionTestParameterValuesProvider. - Added support for repeated annotations to
TestParameterValuesProvider.Context - Converting incorrectly YAML-parsed booleans back to their enum values when possible
- Support enum aliases (defined as static fields on the enum), and in particular Protocol Buffer enum aliases
- When generating test names for enum values, the enum name is used instead of
its
toString()method.
-
Add context aware version of
TestParameterValuesProvider. It is the same as the oldTestParameter.TestParameterValuesProvider, except thatprovideValues()was changed toprovideValues(Context)whereContextcontains the test class and the other annotations. This allows for more generic providers that take into account custom annotations with extra data, or the implementation of abstract methods on a base test class.Example usage:
import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider;
private static final class MyProvider extends TestParameterValuesProvider {
@Override
public List<?> provideValues(Context context) throws Exception {
var testInstance = context.testClass().getDeclaredConstructor().newInstance();
var fooList = ((MyBaseTestClass) testInstance).getFooList();
// ...
// OR
var fooList = context.getOtherAnnotation(MyCustomAnnotation.class).fooList();
// ...
}
}- Fixed some theoretical non-determinism that could arise from Java reflection methods
- Fixed multiple constructors error when this library is used with Powermock. See #40.
- Add support for setting a custom name for a
@TestParametervalue given via a provider:
private static final class FruitProvider implements TestParameterValuesProvider {
@Override
public List<?> provideValues() {
return ImmutableList.of(
value(new Apple()).withName("apple"),
value(new Banana()).withName("banana"));
}
}- Add support for
BigIntegerandUnsignedLong - JUnit4: Fix for interrupted test cases causing random failures with thread reuse (porting the earlier fix in JUnit4)
- Tweak to the test name generation: Show the parameter name if its value is potentially ambiguous (e.g. null, "" or "123").
- Made
TestParametersValues.name()optional. If missing, a name will be generated.
- Replaced deprecated call to org.yaml.snakeyaml.constructor.SafeConstructor
- Removed dependency on
protobuf-javalite(see issue #24)
- Bugfix: Support explicit ordering by the JUnit4
@Rule. For example:@Rule(ordering=3). - Potential test name change: Test names are no longer dependent on the locale of the machine
running it (e.g. doubles with integer values are always formatted with a trailing
.0)
- Add support for JUnit5 (Jupiter)
- Remove
TestParameterInjectorsupport fororg.junit.runners.Parameterized, which was undocumented and thus unlikely to be used.
- Bugfixes
- Better documentation
@TestParameterscan now also be used as a repeated annotation:
// Newly added and recommended for new code
@Test
@TestParameters("{age: 17, expectIsAdult: false}")
@TestParameters("{age: 22, expectIsAdult: true}")
public void withRepeatedAnnotation(int age, boolean expectIsAdult){...}
// The old way of using @TestParameters is still supported
@Test
@TestParameters({
"{age: 17, expectIsAdult: false}",
"{age: 22, expectIsAdult: true}",
})
public void withSingleAnnotation(int age, boolean expectIsAdult){...}@TestParameterssupports setting a custom test name:
@Test
@TestParameters(customName = "teenager", value = "{age: 17, expectIsAdult: false}")
@TestParameters(customName = "young adult", value = "{age: 22, expectIsAdult: true}")
public void personIsAdult(int age, boolean expectIsAdult){...}- Test names with very long parameter strings are abbreviated differentily: In some cases, more characters are allowed.
- Bugfix: Run test methods declared in a base class (instead of throwing an exception)
- Test names with very long parameter strings are now abbreviated with a snippet of the shortened parameter
- Duplicate test names are given a suffix for deduplication
- Replaced dependency on
protobuf-javaby a dependency onprotobuf-javalite
- Treat 'null' as a magic string that results in a null value
- Don't use the parameter name if it's not explicitly provided by the compiler
- Add support for older Android SDK versions by removing the dependency on
j.l.r.Parameter. The minimum Android SDK version is now 24.
- Add support for
ByteStringandbyte[]