Add lifecycle module: @BeforeAll/@AfterAll demos on JUnit 6.1.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
@BeforeAll static (no instance yet)
|
||||
a() instance=342198178
|
||||
b() instance=1988644427
|
||||
@AfterAll static
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL b()
|
||||
SUCCESSFUL Fixtures$StaticHooks
|
||||
@@ -0,0 +1,8 @@
|
||||
@BeforeAll instance, counter=100
|
||||
a() instance=18179709 counter=101
|
||||
b() instance=18179709 counter=102
|
||||
@AfterAll instance, counter=102
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL b()
|
||||
SUCCESSFUL Fixtures$PerClassHooks
|
||||
@@ -0,0 +1,6 @@
|
||||
-- results --
|
||||
FAILED <engine> DiscoveryIssueException: TestEngine with ID 'junit-jupiter' encountered a critical issue during test discovery:
|
||||
|
||||
(1) [ERROR] @BeforeAll method 'void com.ankurm.tutorials.junit.lifecycle.Fixtures$NonStaticWithoutPerClass.setupAll()' must be static unless the test class is annotated with @TestInstance(Lifecycle.PER_CLASS).
|
||||
Source: MethodSource [className = 'com.ankurm.tutorials.junit.lifecycle.Fixtures$NonStaticWithoutPerClass', methodName = 'setupAll', methodParameterTypes = '']
|
||||
at com.ankurm.tutorials.junit.lifecycle.Fixtures$NonStaticWithoutPerClass.setupAll(SourceFile:0)
|
||||
@@ -0,0 +1,4 @@
|
||||
@BeforeAll start: about to fail
|
||||
@AfterAll stop: resource is null
|
||||
-- results --
|
||||
FAILED Fixtures$BeforeAllFails IllegalStateException: container did not start
|
||||
@@ -0,0 +1,4 @@
|
||||
@AfterAll stop (unguarded)
|
||||
-- results --
|
||||
FAILED Fixtures$BeforeAllFailsUnguarded IllegalStateException: container did not start
|
||||
suppressed NullPointerException: Cannot invoke "java.lang.AutoCloseable.close()" because "com.ankurm.tutorials.junit.lifecycle.Fixtures$BeforeAllFailsUnguarded.resource" is null
|
||||
@@ -0,0 +1,6 @@
|
||||
a() ran
|
||||
@AfterAll closeDatabase
|
||||
@AfterAll deleteFiles
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
FAILED Fixtures$AfterAllThrows IllegalStateException: db close failed
|
||||
@@ -0,0 +1,8 @@
|
||||
Base @BeforeAll
|
||||
Sub @BeforeAll
|
||||
Sub a()
|
||||
Sub @AfterAll
|
||||
Base @AfterAll
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL Fixtures$Sub
|
||||
@@ -0,0 +1,6 @@
|
||||
HidingBase.init
|
||||
HidingSub.init
|
||||
HidingSub a()
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL Fixtures$HidingSub
|
||||
@@ -0,0 +1,7 @@
|
||||
second
|
||||
first
|
||||
third
|
||||
a()
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL Fixtures$TwoBeforeAllInOneClass
|
||||
@@ -0,0 +1,11 @@
|
||||
Outer @BeforeAll
|
||||
outer test
|
||||
Inner static @BeforeAll
|
||||
inner test
|
||||
Inner static @AfterAll
|
||||
Outer @AfterAll
|
||||
-- results --
|
||||
SUCCESSFUL outerTest()
|
||||
SUCCESSFUL innerTest()
|
||||
SUCCESSFUL Inner
|
||||
SUCCESSFUL Fixtures$OuterWithNested
|
||||
@@ -0,0 +1,8 @@
|
||||
@BeforeAll seeded junit-<n>
|
||||
a() reads: seeded once
|
||||
b() reads: seeded once
|
||||
@AfterAll dir still exists: true
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL b()
|
||||
SUCCESSFUL Fixtures$SharedTempDir
|
||||
@@ -0,0 +1,9 @@
|
||||
server STARTED
|
||||
UsesServerA test
|
||||
UsesServerB test
|
||||
server CLOSED
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL Fixtures$UsesServerA
|
||||
SUCCESSFUL b()
|
||||
SUCCESSFUL Fixtures$UsesServerB
|
||||
@@ -0,0 +1,5 @@
|
||||
setupAll ran
|
||||
test ran
|
||||
-- results --
|
||||
SUCCESSFUL a()
|
||||
SUCCESSFUL Fixtures$NonStaticWithoutPerClass
|
||||
Reference in New Issue
Block a user