CHC4010 DevOps Week 5 Practical: Automated Testing
Part I. Find the biggest number in the array
In the
exercise1folder, find the fileMax.javaand copy the file into thesrcfolder of your project. Read, execute, and understand the code.Follow the steps demonstrated in the lecture and create an automated test for the
max()method using the testing libraryJUnit5. You should NOT use the same logic in the test as the tested method itself. Don’t fall into the self-test trap!
Part II. A student database implemented with array
Open the
exercise2folder and copy the file insidesrcinto thesrcfolder of your project. Copy the file insidetestinto the test folder of your project (you should have already created a test folder for the previous exercise!).Run
StudentDBTest.javaand you will see that some tests are failing. This is due to a bug ingetStudents()method. FixgetStudents()method inStudentDB.javaso that the test forgetStudents()passed. (It’s okay that other tests might still be failing at this point.)Read the documentation of
addStudent()and create an automated test for this method. Before writing the test code, make list of the functional properties we should test for.Implement
removeStudent()in a way that would pass theremoveStudent()test.In its initial state,
findStudent()uses linear search to find a certain student in the database. Sincestudentsare kept sorted in alphabetical order, we can use binary search to improve efficiency. Adapt thebinarySearch()method given inStudentDB.javaand use it to find a student in the database.
After this change, run the all the tests again. Did your change break any existing feature? Do we need to update the tests for any of the public methods? Why or why not?
[!TIP] 🔗 Practice codes 🔗 Solution codes
Last updated