-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safely generate display name for @ParameterizedTest if argument.toString() throws exception #1492
Comments
Thanks for raising the issue and including a test case that reproduces the behavior! |
AnalysisThis issue occurs because In the provided example |
FYI: I added Deliverables and slated this for 5.3 RC1. |
If/when we implement this, it should be a common utility that we can reuse for assertions etc. as well. |
I also updated the title accordingly. |
@marcphilipp, the code in question already uses So we could either add the exception handling support there or introduce a new method (e.g., |
FWIW, |
I've labeled this as an "enhancement" since I'm not convinced it should qualify as a bug. Thoughts? |
I think changing In any case, I think we shouldn't call |
Sure... at the very least regarding the names. 😛
Ideally, yes, I agree that we should not do that. But it will require slightly more custom code to avoid that. I guess we'd have to figure out if each "consumed argument" is actually referenced in the Thoughts? |
Or... we could pass the |
@johnsoneal, out of curiosity, how did you realize you could return a 2D array from a I don't think I've ever seen anyone do that, and the JavaDoc explicitly states the following.
So, I'm guessing we should update the JavaDoc for |
... and add a test case for it. 😉 |
|
Nice to see I have done something not seen by you guys before! Their where two main reason for doing it this way. First the
And secondly the documentation for
To me this implied I could supply a 2D array and the automatic type conversion would handle the creation of the This was my reasoning, however I guess from your comment this is not the intended usage. |
I agree: quite amusing.
We ultimately use a |
True... it wasn't intentional. But... if it works, it works. |
I just realized this is the Columbus issue: "In August #1492, Columbus sailed the ocean blue." |
Wow, JUnit 5 has now received almost 1500 issues and PRs! I'd consider that a great milestone. 🥂 |
Update:
✅
✅
✅ |
Addressed in 5bada91. |
Prior to this commit, if the toString() implementation of an object supplied to nullSafeToString() threw an exception, that exception would simply be allowed to propagate. Consequently, unexpected failures could occur simply because the framework was attempting to safely generate a String representation of a given object. This commit improves the "safety" of nullSafeToString() by catching any exception encountered while attempting to safely generate a String representation. If an exception is caught in the process, nullSafeToString() will now generate a default String representation based on the object's fully qualified class name and system hash code, separated by an "@" symbol. This change affects the following use cases. - The generation of detailed failure messages for failed assertions no longer fails if the toString() implementation of an object supplied to the assertion throws an exception. - Display name generation for a @ParameterizedTest no longer fails if the toString() implementation of an argument for the parameterized test throws an exception. - The use of ToStringBuilder for building strings is now safer. Issue: junit-team#1492
…arate package with basic event timing Refactored to -tck format with package name changes + added concept of TestExecution + TerminationInfo SpotlessApply for checkstyle fixes Corrected README Refactored to junit-platform-test and pulled in testArtifact classes from junit-platform-engine Starting javadocs Corrected imports and styling Consolidated some of the API calls for execution recorder + javadocs / API docs ./gradlew spotlessApply Switched to using Instant for execution timings and minor refactoring Fix javadoc NPE by removing {@link} references to generics. Relevant ticket here: https://bugs.openjdk.java.net/browse/JDK-8188248 Bumped API version to tagged PR version of platform 1.3.x Fixed platform-tooling-support-tests for junit-platform-test module Refactor to junit-platform-testkit from junit-platform-test Fixed top level build.gradle reference for junit-platform-testkit name Fixed a few typos Fixed expected package in jar-describe-module test Fixed another package typo for jar-describe-module test Suppress warnings in tests Rename test class to DefaultParallelExecutionConfigurationStrategyTests - Added the "s" to "Test" Disable broken tests in DefaultParallelExecutionConfigurationStrategyTests This commit disables tests in DefaultParallelExecutionConfigurationStrategyTests that are broken due to issues with Mockito on Java 10. Issue: junit-team#1478 Fix DefaultParallelExecutionConfigurationStrategyTests Move test task config to testing.gradle - Remove duplication - Rename test classes to adhere to naming convention Simplify test include config in Gradle build Upgrade to Mockito 2.19.0 Upgrade to Maven Surefire 2.22.0 Upgrade to Univocity 2.6.4 Upgrade to Spotless 3.13.0 Upgrade to Dependency Versions plugin 0.20.0 Release 5.3 M1 Back to snapshots for further development Add missing date for 5.3 M1 release Upgrade to Gradle build scan 1.14 Upgrade to Fast Classpath Scanner 3.1.0 Upgrade to JRuby 9.2.0.0 Upgrade to JMH Gradle plugin 0.4.6 Upgrade to Nemerosa Versioning plugin 2.7.1 Upgrade to git-publish plugin 1.0.1 Upgrade to Kotlin 1.2.50 Upgrade to ktlint 0.24.0 Introduce log4j config for platform-tooling-support-tests project Avoid Eclipse build path cycles This commit modifies the test dependencies for the junit-jupiter-engine project so that there are no build path cycles when importing all of the projects into Eclipse. Switch to different mirror for Ant downloads Use latest Ant version Upgrade to Ant 1.10.4 Ant now supports printing the test run summary via the built-in junitlauncher task. This supersedes the need for the SummaryPrintingListener class, which is now removed from the example project. Revert JRuby upgrade due to incompatibility with asciidoctorj This reverts commit 1c3899e. Do not publish to local Maven repo unless necessary This commit reintroduces the change in 84e2abe and adds a comment to explain the rationale. Issue: junit-team#1429 Polish JavaDoc for @ResourceLock Polish JavaDoc for @ResourceLocks Remove default value for @ResourceLocks.value() Added back API functions Refactored method usage in most tests to adhere to original API Add missing @since/@API to Store.getOrComputeIfAbsent(Class) This commit adds the missing @SInCE and @API declarations to ExtensionContext.Store.getOrComputeIfAbsent(Class<V>) that were accidentally omitted in the JUnit 5.1 release. Issue: junit-team#1110 Polishing Polishing Prune Release Notes for 5.3 Closes: junit-team#1480 Introduce skeleton for 5.3 RC1 release notes Introduce "Release Notes" template Improve error message for 0 arg sets for a @ParameterizedTest Issue: junit-team#1477 Fix broken test Use simple class name as display name in JUnit Vintage Prior to this commit, there was a discrepancy between how Jupiter and Vintage generated display names for test classes. Specifically, Jupiter provided short class names as display names; whereas, Vintage provided fully qualified class names. This commit addresses this by using the simple name of the test class as the display in Vintage as well. Issue: junit-team#970 Document change in Release Notes Issue: junit-team#970 Ensure project is built successfully before publishing Polish HierarchicalTestEngine and collaborators Introduce TestInstanceFactory extension API This commit introduces a new TestInstanceFactory extension API that allows for custom creation of test instances. - TestInstanceFactory must be applied at the class level. - If multiple TestInstanceFactory extensions are registered on a single test class, an exception is thrown. - TestInstanceFactory may also be used with @nested test classes, in which case only one TestInstanceFactory is registered on each level. Issue: junit-team#672 Polish TestInstanceFactory implementation Issue: junit-team#672 Move TestInstanceFactory entry to 5.3 RC1 Release Notes Issue: junit-team#672 Polish TestInstanceFactory section in User Guide Issue: junit-team#672 Instantiate converters and aggregators only once per parameterized test Prior to this commit `ArgumentConverter` and `ArgumentsAggregator` classes were instantiated once per invocation of the `@ParameterizedTest`. With this commit, instances will be created during the first invocation of the `@ParameterizedTest` method, stored and reused on subsequent invocations. If the same converter of aggregator classes are used on other `@ParameterizedTest` methods a new instance will be created on first invocation and reused for subsequent invocations of that method. Of the two proposed options to implement this, either eager instantiation or reuse I chose reuse. The rationale was if the instantiation of a Converter of Aggregator failed with an exception this error could be caught with the existing safe mechanism and also for the failure to be very close to the impacting test invocation. Issue: junit-team#1397 Polishing Document junit-team#1397 in Release Notes Resolves junit-team#1397. Closes junit-team#1433. Make TestInstancePostProcessor a @FunctionalInterface Polish TestInstanceFactoryTests Issue: junit-team#672 Ensure TestInstanceFactory can be registered as a lambda expression Issue: junit-team#672 Test exception handling for TestInstanceFactory errors Issue: junit-team#672 Ensure TestInstanceFactory creates object of correct type Issue: junit-team#672 Resolve TestInstanceFactory at class level Prior to this commit, TestInstanceFactory extensions were resolved lazily on-demand. This led to the undesired side effect that configuration errors were reported for each test method when executing with per-method lifecycle semantics. In addition, this also meant that an attempt was made to invoke all test methods even though the test class could not be instantiated. This commit addresses these issues by resolving the TestInstanceFactory during the "prepare" phase for each ClassTestDescriptor. This commit also introduces the following methods in ExtensionRegistry in order to make the above change possible. - getParent() - getLocalExtensions(Class) Issue: junit-team#672 Handle exception thrown by TestInstanceFactory This commit ensures that an exception thrown by a TestInstanceFactory is wrapped in a TestInstantiationException, unless the exception is already a TestInstantiationException in which case it is simply rethrown. Issue: junit-team#672 Allow Assertions and Assumptions classes to be extended Prior to this commit, it was not possible to extend the Assertions and Assumptions classes since they both were final and had private constructors. This commit removes this restriction in order to support unusual circumstances in which it may be "forbidden" to use static imports. Note, however, that a note has been added to the class-level JavaDoc for these classes in order to voice the opinion of the JUnit Team that it is a best practice to use static imports for methods defined in the Assertions and Assumptions classes. Resolves: junit-team#1484 Upgrade Gradle to 4.9-rc-1 Introduce ParameterizedTestMethodContext `ParameterizedTestMethodContext` encapsulates access to the test method parameters' annotations to ensure it is only done once per `@ParameterizedTest` which significantly improves performance for methods with more than a few declared parameters. Resolves junit-team#1483. Upgrade to Gradle build-scan 1.15 Make AnnotationConsumer a @FunctionalInterface Fix and polish JavaDoc for AnnotationConsumer Polish JavaDoc Polish JavaDoc Upgrade to Kotlin 1.2.51 Use single quotes where feasible in Gradle build scripts Print arrays in failure msg for assertThrows(ThrowingSupplier) Prior to this commit, if a lambda expression provided to assertThrows() returned an array instead of throwing an exception, the array included in the failure message was not human-readable. This commit addresses this by delegating to StringUtils.nullSafeToString() in order to properly print arrays as well. Issue: junit-team#1401 Add note regarding CommonParserSettings.setNumberOfRowsToSkip() Improve exception handling for CSV errors This commit introduces custom exception handling for errors that occur while processing the @CsvSource and @CsvFileSource annotations for parameterized tests. In addition to custom error messages, this commit also introduces a dedicated CsvParsingException. Attempt to fix build on Windows Use archive.apache.org to download Ant binaries Prior to this commit a mirror was used to get the current version, 1.10.4, of the Ant binaries. When the next version, like 1.10.5, is released the mirrors usually switch to provide only the new version. This will fail our build. Now, using archive.apache.org to download Ant binaries, the build will continue to work: the archive provides the current and also former releases. Note: Tool.MAVEN already uses the same source. Refine DoD wrt. test coverage Team Decision: Make it more clear to contributors that not just happy paths should be covered by tests Safely parse FilePosition from query string Prior to this commit, FilePosition.fromQuery() would fail (and return an empty Optional) if any query parameter had a non-integer value. This commit fixes this issue by only attempting to parse a query parameter's value as an integer if the parameter's name is "line" or "column". In addition, the parsing algorithm now stops as soon as it has encountered entries for the line and column. Fixes: junit-team#1489 Implement first-one-wins algorithm in FilePosition.fromQuery() Remove unnecessary @API declaration Support classpath resource for custom TestSource in dynamic tests Issue junit-team#1178 introduced support for creating a UriSource (specifically a FileSource, DirectorySource, or DefaultUriSource) from a URI supplied for a dynamic container or dynamic test. This commit further extends that feature by introducing support for creating a ClasspathResourceSource from a URI supplied for a dynamic container or dynamic test if the URI contains the "classpath" scheme. Otherwise, the behavior introduced in junit-team#1178 is used. Issue: junit-team#1467 Add missing Release Notes entry for 5.3 M1 Issue: junit-team#1178 Polish Release Notes for 5.3 M1 Polishing Exceptions in `@AfterEach` methods fail aborted tests Issue: junit-team#1313 Exceptions in `@AfterAll` methods fail aborted containers Issue: junit-team#1313 Make ThrowableCollector configurable This commit generalizes `ThrowableCollector` to take a predicate that is used to decide whether a `Throwable` is aborted or failed execution. The Jupiter engines uses a specialized implementation that treats OTA's `TestAbortedExceptions` as aborting and everything else as failing: `OpenTest4JAwareThrowableCollector`. In addition, this commit introduces `ThrowableCollector.Factory` and lets `HierarchicalTestEngines` create them in order to allow the engine to decide how to configure its `ThrowableCollectors`. For backwards compatibility, the default implementation returns a factory that always creates instances of `OpenTest4JAwareThrowableCollector`. Issue: junit-team#1313 Use diamond notation where possible Polishing Rename keepAlive to keepAliveSeconds Prior to this commit, the Javadoc for `getKeepAlive()` in `ParallelExecutionConfiguration` mistakenly documented that the timeout's unit was milliseconds when in fact `ForkJoinPoolHierarchicalTestExecutorService` used seconds. Now, the property has been renamed to `getKeepSecondsAlive()` and the documentation has been adapted accordingly. Compile tests using Java 10 Simplify configuration of Java compile tasks Spotless! Document result of ArgumentsProvider throwing TestAbortedException Issue: junit-team#1477 Enable all recommended compiler warnings Prior to this commit, we maintained an explicit list of compiler warnings via `-Xlint:<key>` arguments. The list of possible keys grew to 26, as of javac shipped with JDK 10, and we already missed to activate some new warnings. Now all recommended compiler warnings are enabled via the `-Xlint` argument. Disable "method overrides" warnings for test sources Avoid redundant type argument warning on JDK 9+ This commit introduces a concrete implementation of the internal ResultAwareThrowingSupplierAdapter API in order to avoid a warning that results from the use of an anonymous inner class with "redundant type information" that is flagged on JDK 9 and above. Since the code base is still released using JDK 8 as the target environment, we cannot simply use the diamond notation for the anonymous inner class declaration. Upgrade to Gradle 4.9-rc-2 Reuse config from testing.gradle Polishing Limit queue size of dynamic tests Prior to this commit, concurrently executed dynamic tests (e.g. from a Jupiter `@ParameterizedTest`) were forked immediately after being reported even though all worker threads of the `ForkJoinPool` were already busy. Now, we limit the amount of queued work by using `ForkJoinTask.getSurplusQueuedTaskCount()`. We only fork execution if, according to this heuristic, the task can be executed right away. Otherwise, we execute the task in the current thread which effectively blocks further dynamic tests from being reported and queued. Issue: junit-team#1491 Add tests for additional supported @MethodSource return types A discussion in junit-team#1492 made us aware that @MethodSource factory methods can return 2D object arrays as well as other types that were neither tested nor documented. This commit introduces tests for additionally supported return types for @MethodSource factory methods. Issue: junit-team#1492 Starting refactor to minimize code diff noise based on CR Correcting some formatting problems Minimize the codediff by providing existing method calls, preserving order of method declarations, and indentation
…arate package with basic event timing Refactored to -tck format with package name changes + added concept of TestExecution + TerminationInfo SpotlessApply for checkstyle fixes Corrected README Refactored to junit-platform-test and pulled in testArtifact classes from junit-platform-engine Starting javadocs Corrected imports and styling Consolidated some of the API calls for execution recorder + javadocs / API docs ./gradlew spotlessApply Switched to using Instant for execution timings and minor refactoring Fix javadoc NPE by removing {@link} references to generics. Relevant ticket here: https://bugs.openjdk.java.net/browse/JDK-8188248 Bumped API version to tagged PR version of platform 1.3.x Fixed platform-tooling-support-tests for junit-platform-test module Refactor to junit-platform-testkit from junit-platform-test Fixed top level build.gradle reference for junit-platform-testkit name Fixed a few typos Fixed expected package in jar-describe-module test Fixed another package typo for jar-describe-module test Suppress warnings in tests Rename test class to DefaultParallelExecutionConfigurationStrategyTests - Added the "s" to "Test" Disable broken tests in DefaultParallelExecutionConfigurationStrategyTests This commit disables tests in DefaultParallelExecutionConfigurationStrategyTests that are broken due to issues with Mockito on Java 10. Issue: junit-team#1478 Fix DefaultParallelExecutionConfigurationStrategyTests Move test task config to testing.gradle - Remove duplication - Rename test classes to adhere to naming convention Simplify test include config in Gradle build Upgrade to Mockito 2.19.0 Upgrade to Maven Surefire 2.22.0 Upgrade to Univocity 2.6.4 Upgrade to Spotless 3.13.0 Upgrade to Dependency Versions plugin 0.20.0 Release 5.3 M1 Back to snapshots for further development Add missing date for 5.3 M1 release Upgrade to Gradle build scan 1.14 Upgrade to Fast Classpath Scanner 3.1.0 Upgrade to JRuby 9.2.0.0 Upgrade to JMH Gradle plugin 0.4.6 Upgrade to Nemerosa Versioning plugin 2.7.1 Upgrade to git-publish plugin 1.0.1 Upgrade to Kotlin 1.2.50 Upgrade to ktlint 0.24.0 Introduce log4j config for platform-tooling-support-tests project Avoid Eclipse build path cycles This commit modifies the test dependencies for the junit-jupiter-engine project so that there are no build path cycles when importing all of the projects into Eclipse. Switch to different mirror for Ant downloads Use latest Ant version Upgrade to Ant 1.10.4 Ant now supports printing the test run summary via the built-in junitlauncher task. This supersedes the need for the SummaryPrintingListener class, which is now removed from the example project. Revert JRuby upgrade due to incompatibility with asciidoctorj This reverts commit 1c3899e. Do not publish to local Maven repo unless necessary This commit reintroduces the change in 84e2abe and adds a comment to explain the rationale. Issue: junit-team#1429 Polish JavaDoc for @ResourceLock Polish JavaDoc for @ResourceLocks Remove default value for @ResourceLocks.value() Added back API functions Refactored method usage in most tests to adhere to original API Add missing @since/@API to Store.getOrComputeIfAbsent(Class) This commit adds the missing @SInCE and @API declarations to ExtensionContext.Store.getOrComputeIfAbsent(Class<V>) that were accidentally omitted in the JUnit 5.1 release. Issue: junit-team#1110 Polishing Polishing Prune Release Notes for 5.3 Closes: junit-team#1480 Introduce skeleton for 5.3 RC1 release notes Introduce "Release Notes" template Improve error message for 0 arg sets for a @ParameterizedTest Issue: junit-team#1477 Fix broken test Use simple class name as display name in JUnit Vintage Prior to this commit, there was a discrepancy between how Jupiter and Vintage generated display names for test classes. Specifically, Jupiter provided short class names as display names; whereas, Vintage provided fully qualified class names. This commit addresses this by using the simple name of the test class as the display in Vintage as well. Issue: junit-team#970 Document change in Release Notes Issue: junit-team#970 Ensure project is built successfully before publishing Polish HierarchicalTestEngine and collaborators Introduce TestInstanceFactory extension API This commit introduces a new TestInstanceFactory extension API that allows for custom creation of test instances. - TestInstanceFactory must be applied at the class level. - If multiple TestInstanceFactory extensions are registered on a single test class, an exception is thrown. - TestInstanceFactory may also be used with @nested test classes, in which case only one TestInstanceFactory is registered on each level. Issue: junit-team#672 Polish TestInstanceFactory implementation Issue: junit-team#672 Move TestInstanceFactory entry to 5.3 RC1 Release Notes Issue: junit-team#672 Polish TestInstanceFactory section in User Guide Issue: junit-team#672 Instantiate converters and aggregators only once per parameterized test Prior to this commit `ArgumentConverter` and `ArgumentsAggregator` classes were instantiated once per invocation of the `@ParameterizedTest`. With this commit, instances will be created during the first invocation of the `@ParameterizedTest` method, stored and reused on subsequent invocations. If the same converter of aggregator classes are used on other `@ParameterizedTest` methods a new instance will be created on first invocation and reused for subsequent invocations of that method. Of the two proposed options to implement this, either eager instantiation or reuse I chose reuse. The rationale was if the instantiation of a Converter of Aggregator failed with an exception this error could be caught with the existing safe mechanism and also for the failure to be very close to the impacting test invocation. Issue: junit-team#1397 Polishing Document junit-team#1397 in Release Notes Resolves junit-team#1397. Closes junit-team#1433. Make TestInstancePostProcessor a @FunctionalInterface Polish TestInstanceFactoryTests Issue: junit-team#672 Ensure TestInstanceFactory can be registered as a lambda expression Issue: junit-team#672 Test exception handling for TestInstanceFactory errors Issue: junit-team#672 Ensure TestInstanceFactory creates object of correct type Issue: junit-team#672 Resolve TestInstanceFactory at class level Prior to this commit, TestInstanceFactory extensions were resolved lazily on-demand. This led to the undesired side effect that configuration errors were reported for each test method when executing with per-method lifecycle semantics. In addition, this also meant that an attempt was made to invoke all test methods even though the test class could not be instantiated. This commit addresses these issues by resolving the TestInstanceFactory during the "prepare" phase for each ClassTestDescriptor. This commit also introduces the following methods in ExtensionRegistry in order to make the above change possible. - getParent() - getLocalExtensions(Class) Issue: junit-team#672 Handle exception thrown by TestInstanceFactory This commit ensures that an exception thrown by a TestInstanceFactory is wrapped in a TestInstantiationException, unless the exception is already a TestInstantiationException in which case it is simply rethrown. Issue: junit-team#672 Allow Assertions and Assumptions classes to be extended Prior to this commit, it was not possible to extend the Assertions and Assumptions classes since they both were final and had private constructors. This commit removes this restriction in order to support unusual circumstances in which it may be "forbidden" to use static imports. Note, however, that a note has been added to the class-level JavaDoc for these classes in order to voice the opinion of the JUnit Team that it is a best practice to use static imports for methods defined in the Assertions and Assumptions classes. Resolves: junit-team#1484 Upgrade Gradle to 4.9-rc-1 Introduce ParameterizedTestMethodContext `ParameterizedTestMethodContext` encapsulates access to the test method parameters' annotations to ensure it is only done once per `@ParameterizedTest` which significantly improves performance for methods with more than a few declared parameters. Resolves junit-team#1483. Upgrade to Gradle build-scan 1.15 Make AnnotationConsumer a @FunctionalInterface Fix and polish JavaDoc for AnnotationConsumer Polish JavaDoc Polish JavaDoc Upgrade to Kotlin 1.2.51 Use single quotes where feasible in Gradle build scripts Print arrays in failure msg for assertThrows(ThrowingSupplier) Prior to this commit, if a lambda expression provided to assertThrows() returned an array instead of throwing an exception, the array included in the failure message was not human-readable. This commit addresses this by delegating to StringUtils.nullSafeToString() in order to properly print arrays as well. Issue: junit-team#1401 Add note regarding CommonParserSettings.setNumberOfRowsToSkip() Improve exception handling for CSV errors This commit introduces custom exception handling for errors that occur while processing the @CsvSource and @CsvFileSource annotations for parameterized tests. In addition to custom error messages, this commit also introduces a dedicated CsvParsingException. Attempt to fix build on Windows Use archive.apache.org to download Ant binaries Prior to this commit a mirror was used to get the current version, 1.10.4, of the Ant binaries. When the next version, like 1.10.5, is released the mirrors usually switch to provide only the new version. This will fail our build. Now, using archive.apache.org to download Ant binaries, the build will continue to work: the archive provides the current and also former releases. Note: Tool.MAVEN already uses the same source. Refine DoD wrt. test coverage Team Decision: Make it more clear to contributors that not just happy paths should be covered by tests Safely parse FilePosition from query string Prior to this commit, FilePosition.fromQuery() would fail (and return an empty Optional) if any query parameter had a non-integer value. This commit fixes this issue by only attempting to parse a query parameter's value as an integer if the parameter's name is "line" or "column". In addition, the parsing algorithm now stops as soon as it has encountered entries for the line and column. Fixes: junit-team#1489 Implement first-one-wins algorithm in FilePosition.fromQuery() Remove unnecessary @API declaration Support classpath resource for custom TestSource in dynamic tests Issue junit-team#1178 introduced support for creating a UriSource (specifically a FileSource, DirectorySource, or DefaultUriSource) from a URI supplied for a dynamic container or dynamic test. This commit further extends that feature by introducing support for creating a ClasspathResourceSource from a URI supplied for a dynamic container or dynamic test if the URI contains the "classpath" scheme. Otherwise, the behavior introduced in junit-team#1178 is used. Issue: junit-team#1467 Add missing Release Notes entry for 5.3 M1 Issue: junit-team#1178 Polish Release Notes for 5.3 M1 Polishing Exceptions in `@AfterEach` methods fail aborted tests Issue: junit-team#1313 Exceptions in `@AfterAll` methods fail aborted containers Issue: junit-team#1313 Make ThrowableCollector configurable This commit generalizes `ThrowableCollector` to take a predicate that is used to decide whether a `Throwable` is aborted or failed execution. The Jupiter engines uses a specialized implementation that treats OTA's `TestAbortedExceptions` as aborting and everything else as failing: `OpenTest4JAwareThrowableCollector`. In addition, this commit introduces `ThrowableCollector.Factory` and lets `HierarchicalTestEngines` create them in order to allow the engine to decide how to configure its `ThrowableCollectors`. For backwards compatibility, the default implementation returns a factory that always creates instances of `OpenTest4JAwareThrowableCollector`. Issue: junit-team#1313 Use diamond notation where possible Polishing Rename keepAlive to keepAliveSeconds Prior to this commit, the Javadoc for `getKeepAlive()` in `ParallelExecutionConfiguration` mistakenly documented that the timeout's unit was milliseconds when in fact `ForkJoinPoolHierarchicalTestExecutorService` used seconds. Now, the property has been renamed to `getKeepSecondsAlive()` and the documentation has been adapted accordingly. Compile tests using Java 10 Simplify configuration of Java compile tasks Spotless! Document result of ArgumentsProvider throwing TestAbortedException Issue: junit-team#1477 Enable all recommended compiler warnings Prior to this commit, we maintained an explicit list of compiler warnings via `-Xlint:<key>` arguments. The list of possible keys grew to 26, as of javac shipped with JDK 10, and we already missed to activate some new warnings. Now all recommended compiler warnings are enabled via the `-Xlint` argument. Disable "method overrides" warnings for test sources Avoid redundant type argument warning on JDK 9+ This commit introduces a concrete implementation of the internal ResultAwareThrowingSupplierAdapter API in order to avoid a warning that results from the use of an anonymous inner class with "redundant type information" that is flagged on JDK 9 and above. Since the code base is still released using JDK 8 as the target environment, we cannot simply use the diamond notation for the anonymous inner class declaration. Upgrade to Gradle 4.9-rc-2 Reuse config from testing.gradle Polishing Limit queue size of dynamic tests Prior to this commit, concurrently executed dynamic tests (e.g. from a Jupiter `@ParameterizedTest`) were forked immediately after being reported even though all worker threads of the `ForkJoinPool` were already busy. Now, we limit the amount of queued work by using `ForkJoinTask.getSurplusQueuedTaskCount()`. We only fork execution if, according to this heuristic, the task can be executed right away. Otherwise, we execute the task in the current thread which effectively blocks further dynamic tests from being reported and queued. Issue: junit-team#1491 Add tests for additional supported @MethodSource return types A discussion in junit-team#1492 made us aware that @MethodSource factory methods can return 2D object arrays as well as other types that were neither tested nor documented. This commit introduces tests for additionally supported return types for @MethodSource factory methods. Issue: junit-team#1492 Starting refactor to minimize code diff noise based on CR Correcting some formatting problems Minimize the codediff by providing existing method calls, preserving order of method declarations, and indentation
A discussion in junit-team#1492 made us aware that @MethodSource factory methods can return 2D object arrays as well as other types that were neither tested nor documented. This commit introduces tests for additionally supported return types for @MethodSource factory methods. Issue: junit-team#1492
A discussion in junit-team#1492 made us aware that @MethodSource factory methods can return 2D object arrays as well as other types that were neither tested nor documented. This commit introduces additional documentation for supported return types for @MethodSource factory methods. Issue: junit-team#1492
Prior to this commit, if the toString() implementation of an object supplied to nullSafeToString() threw an exception, that exception would simply be allowed to propagate. Consequently, unexpected failures could occur simply because the framework was attempting to safely generate a String representation of a given object. This commit improves the "safety" of nullSafeToString() by catching any exception encountered while attempting to safely generate a String representation. If an exception is caught in the process, nullSafeToString() will now generate a default String representation based on the object's fully qualified class name and system hash code, separated by an "@" symbol. This change affects the following use cases. - The generation of detailed failure messages for failed assertions no longer fails if the toString() implementation of an object supplied to the assertion throws an exception. - Display name generation for a @ParameterizedTest no longer fails if the toString() implementation of an argument for the parameterized test throws an exception. - The use of ToStringBuilder for building strings is now safer. Issue: junit-team#1492
Overview
Using JUnit 5.2.0
I am using parameterized tests, and for the most part everything works as expected. However the name with pattern fails if any object has a bad
toString()
, even if the object is not referenced by the pattern. For example:In the example an exception is thrown as all arguments are formatted not just the specified pattern.
I understand that throwing an exception from
toString()
is a really bad idea; however, it is somewhat unexpected that the formatter is callingtoString()
on arguments that it is not explicitly being asked to format.As a side note, Hamcrest for a similar situation uses a
toString()
that conforms toObject#toString()
:Deliverables
toString()
on arguments supplied to a@ParameterizedTest
method does not prevent generation of the display name.toString()
safely (within a try-catch block).The text was updated successfully, but these errors were encountered: