Skip to content
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

Introduce @SentenceFragment for IndicativeSentences DisplayNameGenerator #4349

Conversation

sbrannen
Copy link
Member

@sbrannen sbrannen commented Feb 26, 2025

Overview

This PR introduces @⁠SentenceFragment for the IndicativeSentences DisplayNameGenerator.

Related Issues

Definition of Done

@sbrannen
Copy link
Member Author

With the status quo of this PR, the following test class...

class DisplayNameGeneratorDemo {

	@Nested
	@IndicativeSentencesGeneration
	@SentenceFragment("A year is a leap year")
	class LeapYearTests {

		@Nested
		@SentenceFragment("(nested)")
		class NestedTests {

			@ParameterizedTest(name = "{0}")
			@ValueSource(ints = { 2016, 2020, 2048 })
			@SentenceFragment("if it is one of the following years")
			void validLeapYear(int year) {
			}
		}
	}
}

Results in a test tree like:

Screenshot 2025-02-26 at 16 57 07

@sbrannen sbrannen force-pushed the issues/4347-sentence-fragment-annotation branch 4 times, most recently from 2bc268d to bb86a1d Compare February 27, 2025 11:51
@sbrannen sbrannen marked this pull request as ready for review February 27, 2025 12:58
@sbrannen

This comment was marked as outdated.

sbrannen added a commit that referenced this pull request Mar 2, 2025
@sbrannen sbrannen force-pushed the issues/4347-sentence-fragment-annotation branch 5 times, most recently from b84ef61 to fd4b608 Compare March 2, 2025 15:54
Prior to this commit, it was not possible to provide a custom display
name for an individual "sentence fragment" for the IndicativeSentences
DisplayNameGenerator.

Although it is possible to register a custom DisplayNameGenerator (such
as ReplaceUnderscores) to affect how a sentence fragment is generated,
you previously could not provide an entire custom sentence fragment. In
addition, attempting to use @⁠DisplayName for a sentence fragment
results in the entire sentence (that would otherwise be generated by
the IndicativeSentences DisplayNameGenerator) getting overridden by the
value of the @⁠DisplayName for the current test class or test
method.

To address that shortcoming, this commit introduces a new
@⁠SentenceFragment annotation that can be used to specify custom
sentence fragments when using the IndicativeSentences
DisplayNameGenerator.

Closes junit-team#4347
Closes junit-team#4349
@sbrannen sbrannen force-pushed the issues/4347-sentence-fragment-annotation branch from fd4b608 to 03023da Compare March 2, 2025 16:34
@sbrannen sbrannen closed this in 02f658e Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce @SentenceFragment for use with IndicativeSentences DisplayNameGenerator
2 participants