1 / 21

Unit Testing in Eclipse

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.

dwilbur
Download Presentation

Unit Testing in Eclipse

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit Testing in Eclipse Presented by David Eisler 08/09/2014

  2. 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

  3. 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)

  4. What is Unit Testing • Testing bits of code in isolation with test code.

  5. 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.

  6. 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?

  7. JUnit • JUnit in version 4.x (what we are using) is a test framework which uses annotations to identify methods that specify a test.

  8. JUnit Annotations 1/2

  9. JUnit Annotations 2/2

  10. Assertions 1/2

  11. Assertions 2/2

  12. Multiply Demo Create a Java Class:

  13. Create new Package called tests: • New>Package • Name new package tests • Right click new package tests>Build Path>Use as source folder

  14. Create a JUnit test • Right click project • New>JUnit Test Case

  15. Wizard allows you to auto-create method stubs:

  16. Prompts to add Junit 4 library jar to build path:

  17. Resulting Class:

  18. testExceptionIsThrown &testMultiply

  19. Run your test in Eclipse: • Right click test class>Run As>JUnit Test

  20. Fix the error:

  21. Passed!

More Related