Lab 12: Unit Tests for Shuffles

In this lab, you will write unit tests for the “Shuffles, part 1” homework.

If you are working on this homework with a partner, you should work on this lab together. If you are working on the homework individually, you should work on this lab individually.

Instructions

You are developing two classes for the homework: Card and ArrayDeck. You should create corresponding test classes for each of these (i.e., CardTests, and ArrayDeckTests).

You should write unit tests using JUnit 5 Jupiter (version 5.4.2). You may find it helpful to consult ExampleTests, the slides, and the resources linked below:

You should write at least one unit test for each of the methods described in the assignment. For example, you should write at least one test for Card’s toString method. In some tests, it may make sense to use multiple assertions. Together, your tests should exercise all the functionality described in the assignment. To fully test my code, I wrote 8 tests, with 16 assertions total.

Hint: JUnit can test that code throws exceptions appropriately. To do this, JUnit uses “lambda expressions.” Here is an example of an assertion that uses a lambda expression:

Assertions.assertThrows(java.lang.IllegalArgumentException.class,
                        () -> {new ArrayDeck(0);});

The second argument to assertThrows() is a lambda expression. This lambda expression describes the code that should be run to cause the IllegalArgumentException to be thrown (i.e., new ArrayDeck(0);). Lambda expressions allow you to pass code as an argument.

Note: If the option to run your new test class (e.g., CardTests) doesn’t appear in the “Run …” dialogue, contact the instructor for help – you may need to edit the project configuration.

Submit

Complete the “Lab 12: Unit Tests for Shuffles” quiz on Canvas. You should submit a screenshot showing:

This lab will be graded for completion, as part of your attendance and participation grade. However, to be counted towards your grade, you must write and run unit tests for both classes.

If you worked with a partner, each of you should submit the quiz on Canvas, since there isn’t an easy way to join groups on Canvas.