Skip to content

Commit

Permalink
Update demos and diagrams for lifecycle callbacks
Browse files Browse the repository at this point in the history
Issue: #1620
  • Loading branch information
sbrannen committed Feb 5, 2019
1 parent 3804182 commit a1fb439
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
10 changes: 10 additions & 0 deletions documentation/src/docs/asciidoc/user-guide/extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ please consult the respective Javadoc for each annotation and extension.
JUnit Jupiter guarantees wrapping behavior within class hierarchies for user-supplied
lifecycle callbacks (e.g., `@BeforeEach` and `@AfterEach`):

////
PNG generated using ZenUML: https://app.zenuml.com
See corresponding *.txt file in images folder for the source.
////
image::extensions_DatabaseTestsDemo.png[caption='',title='DatabaseTestsDemo.java']

JUnit Jupiter does **not** guarantee the order in which multiple lifecycle methods are
Expand All @@ -647,6 +652,11 @@ test methods in the same order, thereby allowing for repeatable builds.
In addition, and more importantly, JUnit Jupiter does **not** support wrapping behavior
for multiple lifecycle methods declared within a single test class or test interface.

////
PNG generated using ZenUML: https://app.zenuml.com
See corresponding *.txt file in images folder for the source.
////
image::extensions_BrokenLifecycleMethodConfigDemo.png[caption='',title='BrokenLifecycleMethodConfigDemo.java']

Due to the aforementioned behavior, the JUnit Team recommends that developers declare at
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@Starter(Platform)
Result = JupiterEngine.execute("BrokenLifecycleMethodConfigDemo.testDatabaseFunctionality") {
Result = JupiterEngine.execute(BrokenLifecycleMethodConfigDemo) {

Extension1.beforeEach()
Extension2.beforeEach()
// @BeforeEach
Expand All @@ -11,7 +12,8 @@ Result = JupiterEngine.execute("BrokenLifecycleMethodConfigDemo.testDatabaseFunc
// @AfterEach
BrokenLifecycleMethodConfigDemo.disconnectFromDatabase()
// @AfterEach
BrokenLifecycleMethodConfigDemo.deleteTestDataInDatabase()
BrokenLifecycleMethodConfigDemo.deleteTestDataFromDatabase()
Extension2.afterEach()
Extension1.afterEach()

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@Starter(Platform)
Result = JupiterEngine.execute("DatabaseTestsDemo.testDatabaseFunctionality") {
Result = JupiterEngine.execute(DatabaseTestsDemo) {

// @BeforeAll inherited from AbstractDatabaseTests
DatabaseTestsDemo.createDatabase()
// @BeforeAll
DatabaseTestsDemo.beforeAll()
Extension1.beforeEach()
Extension2.beforeEach()
// @BeforeEach inherited from AbstractDatabaseTests
Expand All @@ -9,9 +14,14 @@ Result = JupiterEngine.execute("DatabaseTestsDemo.testDatabaseFunctionality") {
// @Test
DatabaseTestsDemo.testDatabaseFunctionality()
// @AfterEach
DatabaseTestsDemo.deleteTestDataInDatabase()
DatabaseTestsDemo.deleteTestDataFromDatabase()
// @AfterEach inherited from AbstractDatabaseTests
DatabaseTestsDemo.disconnectFromDatabase()
Extension2.afterEach()
Extension1.afterEach()
// @BeforeAll
DatabaseTestsDemo.afterAll()
// @AfterAll inherited from AbstractDatabaseTests
DatabaseTestsDemo.destroyDatabase()

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void testDatabaseFunctionality() {
}

@AfterEach
void deleteTestDataInDatabase() {
afterEachMethod(getClass().getSimpleName() + ".deleteTestDataInDatabase()");
void deleteTestDataFromDatabase() {
afterEachMethod(getClass().getSimpleName() + ".deleteTestDataFromDatabase()");
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ void testDatabaseFunctionality() {
}

@AfterEach
void deleteTestDataInDatabase() {
afterEachMethod(getClass().getSimpleName() + ".deleteTestDataInDatabase()");
void deleteTestDataFromDatabase() {
afterEachMethod(getClass().getSimpleName() + ".deleteTestDataFromDatabase()");
}

@AfterAll
static void afterAll() {
beforeAllMethod(DatabaseTestsDemo.class.getSimpleName() + ".beforeAll()");
beforeAllMethod(DatabaseTestsDemo.class.getSimpleName() + ".afterAll()");
}

}

1 comment on commit a1fb439

@sormuras
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.