Skip to content

Commit

Permalink
Support Serenity annotations on non-public test method (@title, @With…
Browse files Browse the repository at this point in the history
…Tag) #21

* upgrade to Serenity 2.3.9
  * Consider annotations on non-public test methods (TestAnnotations)
    * serenity-bdd/serenity-core#2306
  * Ignore stacktrace element for inner interfaces and inner or anonymous classes without a superclass (#2229) #2295
    * serenity-bdd/serenity-core#2295
    * >> removed previously added workaround
  • Loading branch information
fabianlinz committed Dec 8, 2020
1 parent de6bfed commit 223694f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 175 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For teams using JUnit to declare the Serenity scenarios, the difference is somet
* different extension mechanism: JUnit4 Rule vs. JUnit5 Extension

## Notes on supported features
### Junit5 `@Disabled` vs Serenity `@Pending`
### Junit5 `@Disabled` vs. Serenity `@Pending`
* Junit5 `@Disabled` annotation can be used on *test* and *step* methods
* The following table outlines the difference of using JUnit5 `@Disabled` and Serenity `@Pending` on a step method

Expand Down Expand Up @@ -85,20 +85,20 @@ For teams using JUnit to declare the Serenity scenarios, the difference is somet
* JUnit5: https://junit.org/junit5/docs/current/user-guide/#writing-tests-tagging-and-filtering
* Serenity: http://thucydides.info/docs/serenity-staging/#_filtering_test_executing_with_tags

### Other
* Serenity `@Title` is considered for the Serenity report (http://thucydides.info/docs/serenity-staging/#_human_readable_method_titles)
* Consistently with Junit4 the `@Title` annotation does not influence the name in the Junit report.

# Known limitations/currently not supported features:

## Serenity BDD features
* `@WithTag` and `@WithTagValuesOf` (http://thucydides.info/docs/serenity-staging/#_filtering_test_executing_with_tags)
* Tags are shown in the report only for methods and declared as `public`. ([#21](https://github.com/fabianlinz/serenity-junit5/issues/21))
* `@WithTag` and `@WithTagValuesOf` (http://thucydides.info/docs/serenity-staging/#_filtering_test_executing_with_tags)
* Filtering of tests not yet possible => works with JUnit5 `@Tag` though ([#22](https://github.com/fabianlinz/serenity-junit5/issues/22))
* `@Title` (http://thucydides.info/docs/serenity-staging/#_human_readable_method_titles)
* The title is not considered for the Serenity report unless the method is delcared as `public` ([#21](https://github.com/fabianlinz/serenity-junit5/issues/21)) nor as test name from JUnit perspective
* Consistently with Junit4 the `@Title` annotation does not influence the name in the Junit report.
* Retrying failed tests
* http://thucydides.info/docs/serenity-staging/#_retrying_failed_tests
* SerenityParameterizedRunner (including Serenity `@Concurrent`)
* http://thucydides.info/docs/serenity-staging/#_data_driven_tests
* Overlap to JUnit5 parameterized test support
* Retrying failed tests
* http://thucydides.info/docs/serenity-staging/#_retrying_failed_tests
* Difference for WebDriver configuration on method level (compared to JUnit4)
* If the test method is annotated with @WithDriver the specified driver is also used for an @Managed field of type WebDriver without an explicit driver type.
In JUnit4 the @Managed field would be the general default web driver. As this seems arbitrary anyway this difference seems to be acceptable in order to not further complicate the implementation.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
logbackVersion = 1.2.3
serenityCoreVersion = 2.3.8
serenityCoreVersion = 2.3.9
junit5Version = 5.7.0
junitTestKitVersion = 1.7.0
assertJVersion = 3.13.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void shouldHaveTwoSimpleTagsViaGroup() {
@Test
@Tag("junit5Tag")
@WithTag("serenityTag")
// TODO until https://github.com/fabianlinz/serenity-junit5/issues/21 is fixed Serenity tag annotation are only considered on public methods
public void shouldAllowUsageOfSerenityAndJunit5TagsTogether() {
void shouldAllowUsageOfSerenityAndJunit5TagsTogether() {
// does not make sense though
}

Expand All @@ -58,7 +57,7 @@ void junit5FeatureTag() {

@Test
@WithTag(name = "serenityFeatureTag")
public void serenityFeatureTag() {
void serenityFeatureTag() {
// does not make sense though
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package starter;

import net.serenitybdd.junit5.SerenityTest;
import net.thucydides.core.annotations.Manual;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.annotations.Title;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand All @@ -27,4 +26,9 @@ void successfulTest() {
assumeTrue(true);
}

@Test
@Title("An explicit title for the test.")
void testWithTitle() {

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ static class UsageOfSerenityAndJunit5TagsTogether {
@WithTag("serenityTag"),
@WithTag(name = "serenityFeatureTag")
})
// TODO until https://github.com/fabianlinz/serenity-junit5/issues/21 is fixed Serenity tag annotation are only considered on public methods
public void test() {
void test() {
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.serenitybdd.junit5.extension;

import net.serenitybdd.junit5.extension.testsupport.SerenityExtensionInnerTest;
import net.serenitybdd.junit5.extension.testsupport.SerenityExtensionTest;
import net.thucydides.core.annotations.Steps;
import net.thucydides.core.annotations.Title;
import org.junit.jupiter.api.Test;

@SerenityExtensionTest
class WhenRunningTitleTests {

@Steps
private JUnit5Steps junit5;

@Test
void the_outcome_should_honor_the_declared_title() {
// when
junit5.executesTestClass(TestWithTitle.class);

// then
junit5.shouldHaveExactlyOneTestOutcome();
junit5.outcomeShouldHaveTitle("explicit test title");
}

@SerenityExtensionInnerTest
static class TestWithTitle {
@Test
@Title("explicit test title")
void testWithTitle() {
}
}
}

0 comments on commit 223694f

Please sign in to comment.