Homework 4
caution
- You are expected to work individually.
- Due: Monday March 31st at 11pm EST (Baltimore time).
- This assignment is worth 62 points.
Objectives
- Testing Randomness and I/O
- Rest API Testing
- CI/CD, Github Actions, Docker
tip
You can get all the starter files for task 4 this homework by doing a git pull
on the course public repo. The files can be found under hw/hw4
.
#
Task 1 (20 points)Using JUnit 5 and rest-assured, write separate unit tests to test the following end points on https://jsonplaceholder.typicode.com/:
- [test 1]: when a
GET
request is sent to/albums
endpoint, verify that an entry with thetitle
"omnis laborum odio" exists. - [test 2]: when a
GET
request is sent to/comments
endpoint, verify that the returned JSON response contains at least 200 comments. - [test 3]: when a
GET
request is sent to/users
endpoint, verify that a user named "Ervin Howell" with username "Antonette" and zipcode of "90566-7771" exists. - [test 4]: when a
GET
request is sent to/comments
endpoint, verify that there are comments from people whose email address end in.biz
. - [test 5]: Create a new post by sending a http
POST
request to/posts
endpoint with this info:
tip
You will find rest-assured
's "Getting Started" and "User Guide" documentations helpful to develop the above tests.
Deliverables
The deliverables for this part are your separate JUnit tests, for the 5 test scenarios mentioned above, saved in a java class named JsonplaceholderRestAPITest.java
saved under task1
folder.
#
Task 2 (25 points)You need to unit test the guessingNumberGame
function within GuessNumber
class.
#
Task 2-1The function implements a number-guessing game. Read the documentation and play the game to develop an understanding of the game. Write JUnit tests to verify that the function behaves as expected (as specified in the documentation). Write your tests in a class named GuessNumberIOTest
. You must write as many different test cases as you can here and aim to reveal as many faults as you can. For each successful test case (i.e., a test case that fails), make a comment on top of it and explain in details why you think this failure is happening and provide a possible description of the underlying fault.
tip
Since the function under test here mainly works with standard i/o, you need to use the techniques discussed in class to successfully test this funciton.
tip
You may run the jar file in a terminal via the command java -cp ./guessnumber.jar GuessNumber
.
tip
The folder named doc
inside task2
contains the documentation of the program in html format.
#
Task 2-2As given in the documentation, the guessingNumberGame
function returns the randomly generated number. In this part, your task is to probe the distribution of the random numbers generated. In particular, you need to verify that the random numbers generated (i.e., the return value of the function) has (roughly) a uniform distribution. To this aim, you are asked to have the funciton run 100,000 30,000 times and store the results of the return random numbers. Fix the seed value at 0 on the random generator you pass in for all runs. Verify that all numbers between 1 and 100 (inclusive) are generated roughly with similar frequency. In this case, we consider the frequencies to be roughly the same if the frequency of generating any of the numbers is within +50%/-50% of any other numbers in the range. You need to implement this in a JUnit test class named GuessNumberRandomnessTest
.
tip
You can make use of or do something similar to what you did in the previous part to automate these runs!
Deliverables
The deliverables for this part are 1) task 3-1: your tests saved in a java class named GuessNumberIOTest.java
, and 2) task 3-2: your tests saved in a java class named GuessNumberRandomnessTest.java
. Save both of these files under task2
folder.
#
Task 3 (17 points)This task requires you to submit what you finished for the "Task" part in exercise 12, the only difference being the pipeline here must fail if the code coverage OR branch coverage is less than the provious run of the pipeline.
tip
consult the specs of cicirello/jacoco-badge-generator
action on Github Action (or specs of the alternate the action that you are using) on how to enable these switches.
Deliverables
The deliverables for this part are: 1) the complete project folder stored in task3
folder, 2) url to the github repo where all files are stored. Make sure to make this github repo public for the time being so we can verify your files and repo, and 3) url to the published (public) image on docker hub. Store the last two items in a file named task3.md
inside the task3
folder`.
#
SubmissionSubmission
Submissions should be made to Gradescope. Create a zip file named hw4.zip
which contains all the deliverables for all the parts. For each task, create a separate folder named taskX, where X is the part number, under which you put all the deliverables for that task. For each task, make sure to submit all the necessary deliverables including JUnit test classes (.java
files NOT .class
files), documents, reports etc.
danger
Important Note: If any of your .java
files is not compilable/executable for any reason, you will receive a zero for that part. Thus, please make sure all the source files you hand in successfully compile and run!