DEV Community

Kotlin (opens in new tab)

Discussed on DEV

๐Ÿงช JUnit Test Isolation โ€” One Small Detail That Changed Everything Today I learned that JUnit creates a brand-new instance of your test class for every " "@TestInstance(TestInstance.Lifecycle.PER_METHOD)" What happens? "test1()" runs โ†’ counter becomes "1" JUnit destroys that object "test2()" gets a fresh instance โ†’ counter starts at "0" again and becomes "2" This prevents tests from accidentally sharing state and affecting each other. ๐Ÿ“ Bonus Gradle Gotcha: If your tests are inside "src/main/k...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help