Download presentation
Presentation is loading. Please wait.
Published bySolomon Adams Modified over 9 years ago
1
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick
2
How can you test your code? SE-2030 Dr. Rob Hasker 2
3
How can you test your app? Run the app with inputs that should produce a known output, and verify the actual output One problem with this approach may be that you can’t make your app accept “bad” inputs; thus you may not be able to force all possible if-then-else blocks of the app’s classes’ methods to execute Write a separate “test” program that is designed to exercise the classes and methods of the “production” app A problem with this might be gathering the results of the exercises and determining whether each one passed or failed. SE-2030 Dr. Rob Hasker 3
4
What is Unit Testing? Creating special-purpose test code that exercises specific classes of your application is called Unit Testing Such test code usually exercises one method at a time (or a small set) whenever possible. The tests usually include exercising the methods in “boundary conditions” by force- feeding the methods “bad” arguments, such as nulls. SE-2030 Dr. Rob Hasker 4
5
What is JUnit? JUnit is an open source Java testing framework used to write and run repeatable tests. It is built in to Eclipse. JUnit provides a framework for executing tests General form of tests: create data, check results Operations to check results: assertEquals, assertTrue, assertFalse, etc. Minimal work needed by developer to set up, run tests SE-2030 Dr. Rob Hasker 5
6
Demonstration SE-2030 Dr. Rob Hasker 6
7
Assertions in Junit See http://junit.sourceforge.net/javadoc/http://junit.sourceforge.net/javadoc/ assertEquals assertTrue assertFalse assertNotSame assertNull assertArrayEquals fail SE-2030 Dr. Rob Hasker 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.