210 likes | 226 Views
Learn the basics of unit testing, JUnit usage, and creating test cases in Eclipse. Understand the benefits, cons, and how to run tests effectively.
E N D
Unit Testing in Eclipse Presented by David Eisler 08/09/2014
Agenda • Pre-Requirements • Unit Testing • JUnit • Multiply Demo • For a more comprehensive overview of Junit in Eclipse see: http://www.vogella.com/tutorials/JUnit/article.html
Pre-Requirements • Eclipse. I am using Eclipse Standard 4.4 (Luna) for 64 bit version in this tutorial. • You can download Eclipse at: https://www.eclipse.org/downloads/ • Eclipse will run on most Windows and Linux OS’s (See previous link)
What is Unit Testing • Testing bits of code in isolation with test code.
Why Do We Care about Unit Testing? • Regression testing • Allows you to make big changes to code quickly with confidence. • Documented proof of testing. • Ultimate goal is to save time and money in the long run by catching bugs sooner.
Cons of Unit Testing • All code is subject to bugs. • Big time investment. You have to write the tests and maintain them. • Additional Complexity. So is it worth it?
JUnit • JUnit in version 4.x (what we are using) is a test framework which uses annotations to identify methods that specify a test.
Multiply Demo Create a Java Class:
Create new Package called tests: • New>Package • Name new package tests • Right click new package tests>Build Path>Use as source folder
Create a JUnit test • Right click project • New>JUnit Test Case
Run your test in Eclipse: • Right click test class>Run As>JUnit Test