COMPSCI 61B Lecture Notes - Lecture 7: Junit, Unit Testing, Selection Sort
Document Summary
Suppose we want to write a class sort that prints sorted command line arguments: Sort will have following methods: static void sort(string[] a): sorts an array of strings static void print(string[] a): prints an array of strings static void main(string[] args): prints the args in sorted order. Writing tests to compare all elements of arrays is sometimes slow, annoying, and di cult. Using org. junit is helpful since it has built-in tools to compare arrays. Sometimes task is unclear until you try something. Optional: refactor code to make it faster, cleaner, etc. A complementary approach to unit testing: integration testing. Unit testing is not enough to ensure modules interact properly or that system works as expected. Testing at highest level of abstraction may miss subtle or rare errors. Selection sort the remaining n - 1 items (without touching the front item!) Use import statements and @test annotations to prevent writing main method and org. junit every time for assert statements.