From the course: Java: Testing with JUnit
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: Refactoring
From the course: Java: Testing with JUnit
Solution: Refactoring
- [Instructor] I'm going to refactor the code so that I don't need the initialization in both the methods as the first line. The first thing I'm going to do is I'm going to add the calculator as a property of our test class. Then I'm going to annotate the setup @BeforeEach, but please mind, in order to use BeforeEach, I have to go ahead and add an import. Inside my for each, I'm going to initialize the calculator. And I'm going to remove this initialization from both the methods. Now, I go ahead and test my code, and as you can see, it is correct, and I have correctly refactored this code.
Contents
-
-
-
-
-
(Locked)
Dependency injection in your tests5m 7s
-
Repeated tests2m 55s
-
(Locked)
Parameterized tests9m 29s
-
(Locked)
Timeouts4m 49s
-
(Locked)
Parallel execution3m 42s
-
(Locked)
Lifecyle control: Before and after5m 10s
-
(Locked)
Custom messages and reports4m 28s
-
(Locked)
Conditional test execution4m 19s
-
(Locked)
Disabling unit tests1m 45s
-
(Locked)
Solution: Refactoring1m 1s
-
(Locked)
-
-