Exercise 11
info
This is an in-class exercise. An exercise page like this one will contain a brief description but is intended to be supplemented by discussion during our meeting time. Complete the exercise to the best of your ability in the time given. Feel free to talk with other students as you work, and do not be afraid to ask questions. Aim to complete as much as possible during our meeting and continue to work at home to finish, but you need not hand it in.
#
Learning ObjectivesObjectives
This exercise should help you practice with:
- Unit testing randomness
- Unit testing methods/classes that do i/o
- REST API testing
- rest-assured tool
#
Answer the following questionsWhat are some of the techniques to unit test methods/classes that work with (psuedo)random generators?
How do you unit test a method that does not return anything but writes to standard output? What if it outputs to a file?
#
Task 1Consider the following "collectThenPrint" helper method that reads size of an int array from standard inout, then collects that many integers, and finnaly prints the content of the array to standard output:
write a unit test to verify that collectThenPrint
indeed collects "4, {1, 2, 3, 4}" from standard Input and and then prints the content of the array "{1, 2, 3, 4}" correctly on standard ouput.
#
Task 2Get a free API key to work with JHU SIS API from here if you do not have one already. Utilizing rest-assured,
- Assert that the
Carey Business School
exists within JHU. - Assert that the course
Data Structures
is offered withinWhiting School of Engineering
in the current academic term - Assert that sending a
post
request to a SIS endpoint returns the status error code405
.
#
ExtraRewrite the above test cases using Postman or a similar standalone rest api testing framework.