Initializing Tests with @Before Methods
We will learn the importance of initializing and refactoring tests with @Before Methods.
We'll cover the following
The @Before
annotation is used to denote methods when we need to execute some common code before running a test. The first thing to look at is the common initialization code in all (both) of the tests in ProfileTest
.
If both tests have the same logic, we can move that common logic into an
@Before
method. That way, each JUnit first executes code in any methods marked with the@Before
annotation.
Get hands-on with 1400+ tech skills courses.