-
Notifications
You must be signed in to change notification settings - Fork 59
Lesson 5 (Unit Testing)
Courtney Frey edited this page Apr 14, 2022
·
3 revisions
-
Some good practices for writing unit tests, some review from previous learning:
- The AAA pattern for creating tests: Arrange, Act, Assert
- The importance of tests when refactoring code
- How to write tests to make code self-documenting
- Why comments are not the best form of documenting code behavior
-
How to place tests in the correct location within a Java project
-
How to use the
@Test
annotation to mark a test method -
How to use
@Before
to generate test data to be used by each test within a class -
The behavior of
@After
-
How to run JUnit tests as a group, or individually, within IntelliJ
-
How to use common assertion methods:
assertEquals
,assertFalse
,assertTrue
,assertNotNull
- Graded Assignment #2 is open and students will now know how to set up the scaffolding for the testing portion of the assignment
- Welcome to Day 8!
- Assignment 1 is due end of today
- Introduce Assignment 2 after studio
- Review the ideas of automated testing and why it is important
- Touch on adding the
.jar
as a dependency for the project - Cover testing organization
-
main
andtest
packages - Grouping related tests
-
- Talk about tests that use AAAs, are deterministic, relevant, and meaningful
- Java annotations - what are they and what do they do
@Test
@Before
@After
- Running test files and running single tests
- This studio asks students to write tests for a broken method
- Students must fork the started code and start an IntelliJ project from Git
- The instructions for this studio are limited to encourage students to discuss testing strategy
- A good development strategy would be to write the tests for the described behavior, then modify the class to pass the tests
- The final tests themselves may vary, as well as the solution
- Ensure the students are writing tests that will pass the conditions described in the class, not tests that will pass the class as it is written
- Remind them that the solution must account for multiple sets of brackets and nested brackets
- Should they choose to tackle the bonus mission, it is also a flawed class that must be corrected.