2/15/20171CEG 491XFComputer Engineering Project I & IITestingVerification and ValidationWinter 2017CEG 491XF –Design of Computer Based Systems1Content1. Testing Tools for Code Developers2. Junit
2/15/20172JUnit Introduction•JUnit is a regression testing framework•Used by developers to implement unit tests in Java•Goal: Accelerate programming and increase the quality of code.•Part of XUnit family (HTTPUnit, Cactus), CppUnitCEG 491XF –Design of Computer Based Systems2Where Does JUnit Come From?•JUnit’s web site: •Eclipse includes JUnit–Eclipse provides new GUI to run JUnit test cases and suites•You can run your unit tests outside of Eclipse–If you wish using TestRunner–Using JUnit’s WindowSEG 4140 - Introduction3
2/15/20173What is Junit?•Test framework provides tools for:– assertions–running tests–aggregating tests (suites)–reporting results•Philosophy always the same:–Let developers write tests.–Make it easy and painless.–Test early and test oftenCEG 491XF –Design of Computer Based Systems4Eclipse JUnit Setup•Eclipse preferences can be set in the JUnit Preferences window•For the most part you can leave these alone•Filters needed to identify packages, classes, or patterns that should not be shown in the stack trace of a test failure SEG 4140 - Introduction5
2/15/20174Why test? Why Junit?+•Automated tests prove features•Tests retain their value over time and allows others to prove the software still works (as tested). •Confidence, quality, sleep•Effective, open source, integrated•Get to code sooner by writing tests.CEG 491XF –Design of Computer Based Systems6JUnit Test Cases•Test case –Runs multiple tests•Implemented a subclass of TestCase•Define instance variables that store the state of the tests in the class•Initialize TestCaseby overriding setUpmethod•Clean-up after test case is done by overriding tearDownmethodSEG 4140 - Introduction7
2/15/20175Test infectedCEG 491XF –Design of Computer Based Systems8•It’s a Good Thing, no penicillin needed•Immediate gratification with build iterations•Start with “The Simplest Thing That Could Possibly Work”.•Iterate by successive application of design pattern.•Break the cycle of more pressure == fewer tests•Reduce code captivity•If others can test it, others can work on it.Half my time on tests?•Yes, really, half.•You’ll spend less time overall•Time savings on debugging–No time wasted on tracking down a bug introduced days or weeks ago.•What debugger?–Less reliance on time consuming debuggers.CEG 491XF –Design of Computer Based Systems9
2/15/20176Junit Mechanics•Define a subclass of TestCase.