-
Made some internal JUnit4 methods of
TestParameterInjector
public:computeTestMethods()
methodBlock()
methodInvoker()
These allow any client to combine
TestParameterInjector
with another JUnit4 runner by manually creating aTestParameterInjector
instance and calling these methods from the combined JUnit4 runner.
- Added support for parsing
java.time.Duration
from a string. Example:
@Test
public void myTest(@TestParameter({"1d", "2h20min", "10.5ms"}) Duration duration){...}
- Deprecated
TestParameter.TestParameterValuesProvider
in 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)
whereContext
contains 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
@TestParameter
value 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
BigInteger
andUnsignedLong
- 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
TestParameterInjector
support fororg.junit.runners.Parameterized
, which was undocumented and thus unlikely to be used.
- Bugfixes
- Better documentation
@TestParameters
can 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){...}
@TestParameters
supports 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-java
by 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
ByteString
andbyte[]