Skip to content

Lesson 5 (Unit Testing)

Courtney Frey edited this page Apr 14, 2022 · 3 revisions

Lesson 5: Unit Testing

In the prep work for this lesson, the students learned

  1. 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
  2. How to place tests in the correct location within a Java project

  3. How to use the @Test annotation to mark a test method

  4. How to use @Before to generate test data to be used by each test within a class

  5. The behavior of @After

  6. How to run JUnit tests as a group, or individually, within IntelliJ

  7. How to use common assertion methods: assertEquals, assertFalse, assertTrue, assertNotNull

Announcements

For Part-Time Students:

  1. Graded Assignment #2 is open and students will now know how to set up the scaffolding for the testing portion of the assignment

For Full-Time Students:

  • Welcome to Day 8!
  • Assignment 1 is due end of today
  • Introduce Assignment 2 after studio

Large Group Time (Instructor)

Lesson 5 Topics That Require Careful Attention

  1. Review the ideas of automated testing and why it is important
  2. Touch on adding the .jar as a dependency for the project
  3. Cover testing organization
    • main and test packages
    • Grouping related tests
  4. Talk about tests that use AAAs, are deterministic, relevant, and meaningful
  5. Java annotations - what are they and what do they do
    • @Test
    • @Before
    • @After
  6. Running test files and running single tests

Small Group Time: Lesson 5 Studio (TF Notes)

  1. This studio asks students to write tests for a broken method
  2. Students must fork the started code and start an IntelliJ project from Git
  3. The instructions for this studio are limited to encourage students to discuss testing strategy
  4. A good development strategy would be to write the tests for the described behavior, then modify the class to pass the tests
  5. The final tests themselves may vary, as well as the solution
  6. 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
  7. Remind them that the solution must account for multiple sets of brackets and nested brackets
  8. Should they choose to tackle the bonus mission, it is also a flawed class that must be corrected.