setup
function instead of beforeEach
in unit & service level tests
#910
stalniy
started this conversation in
Contribution RFC
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
This RFC processes to change the approach of writing and structuring testing code. Instead of using
beforeEach
with variables that are shared across different tests, it suggests to replace this pattern withsetup
functionMotivation
beforeEach
+ variables add a lot stuff at the beginning of tests, usually this is not easy to understand code with type casting and spies which developer need to reset inafterEach
. Some tests may require a bit different setup from the one defined inbeforeEach
which makes this logic more complicated.setup
function aims to encapsulate this logic into a function that can be called manually in every tests with test specific parametersExamples
Current one
Suggested one
Main benefits
setup
functionsetup
functionsetup
function at the bottom of test suite doesn't force developers to read implementation details, they can first look at test on high level and only if they need to change or understandsetup
function, they will scroll at the bottomDrawbacks
TestInput
Beta Was this translation helpful? Give feedback.
All reactions