A partner exercise to practice using JUnit tests.
- Choose one partner to be Partner A, one partner to Partner B.
- Have ONLY Partner A fork this repository. PARTNER B SHOULD NOT FORK.
- Have Partner A add Partner B as a collaborator on their fork. Follow these directions.
- Have the Partner A send the URL of their repository to Partner B.
- Partner B should see an invitation at the top of the repository. Click "View Invitation", then "Accept Invitation".
- Both partners should clone the repository to their own computer. The URL should include Partner A's username.
- Both partners should change into the project repository:
cd password-checker
- Both partners should open VSCode in the project repository. If the below command does not work, open VS Code and use File > Open Folder.
code .
- Compile the program
javac src/*.java
- Run the program
java -cp src App
- Follow the prompts in the program. Experiment with it and understand what it does.
- Take a brief glance at the
App.java
file to get an overall idea of what it does. Do not dwell too much on fully understanding this file.It is often the case that you will need only to understand part of a program to begin working on it. Learning how to prioritize what parts of a project to deeply understand and which parts to have only a loose understanding of is an important skill to learn!
- Look at
PasswordChecker.java
. Try to understand this code. With your partner, discuss the following:- What does it do?
- How does it do it?
- What are some passwords that would be interesting to check with it?
There are some bugs in this file! If you see them, please do not fix them yet. We will be writing tests that we expect to trigger these bugs.
- Choose one partner to write code first. Use only their computer for this section, but talk to each other and work together on how to do it.
- Open
PasswordChecker.java
. - Anywhere in the file right-click (cmd+click on Mac).
- Choose
Source Action
from the context menu. - Choose
Generate Tests
. - You will likely see an error pop up in the bottom right:
No test library found in your workspace, please add a test library to your project classpath first.
- Click
Enable Tests
on the error pop up - Choose JUnit Jupiter
- Go back to the file and right click again.
- Choose
Source Action
again. - Choose
Generate Tests
again. - Choose JUnit5.
- Check the checkboxes for the public methods (not constructors).
- A test skeleton file should be created.
- Run the empty tests. They should pass.
- Pull, then add, commit, and push the changes.
You will repeatedly follow the below steps for each test you add. For the rest of this assignment you will be switching partners after writing each test. BOTH PARTNERS MUST HAVE COMMITS ON THE REPOSITORY TO RECIEVE CREDIT. Continue following this cycle until the file is thoroughly tested and all bugs are fixed. You should have a minimum of three tests for each public method (not constructor). There should be at least 9 tests overall.
- Switch to the other partner's computer. Pull the changes. If there are merge conflicts, resolve them.
- Create a new test that tests some functionality of the program.
- Run all tests and see if they pass. If they do not pass, determine whether there is an issue in your test or if you found a bug in
PasswordChecker.java
. If there is an issue in your test, fix the test. If there is a bug in password checker, fix the bug. - Once the test is passing, pull, add, commit and push the changes. Go back to the beginning of this section and switch the partner whose computer you are using.
Once you have the file thoroughly tested and all bugs fixed, recompile the program and run the App again.
Reminder: You should have a minimum of three tests for each public method (not constructor). There should be at least 9 tests overall.
Manually verify that the works as expected. If it doesn't, add a test that covers the bug you discovered, then fix the bug and add/commit/push the changes.
Please make a PR to the original repository. Have BOTH partners copy the link to the PR to submit it in Canvas. You will both use the same URL.