1 / 15

JUnit

JUnit. Team segfault Arjun Bhasin Chakori macherla Gunjan raghav Jaideep singh Vicky sehrawat. What is JUnit ?. JUnit is a regression testing framework Used for unit testing framework in Java programs User interface for viewing test results Text GUI

tola
Download Presentation

JUnit

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. JUnit Team segfault ArjunBhasin Chakorimacherla Gunjanraghav Jaideepsingh Vicky sehrawat

  2. What is JUnit? • JUnit is a regression testing framework • Used for unit testing framework in Java programs • User interface for viewing test results • Text • GUI • Integrated with several IDEslike Eclipse • It is one of a family of unit testing frameworks collectively known as xUnit that originated with SUnit.

  3. Who developed JUnit? Written by Erich Gamma and Kent Beck. Used by developers to implement unit tests in Java

  4. Why JUnit? • Test framework provides tools for: • Assertions • Running tests • Aggregating Tests (suites) • Reporting Results • Less reliance on time consuming debuggers • JUnit improves our code quality

  5. Features! JUnit features include: Assertions for testing expected results Test fixtures for sharing common test data Test suites for easily organizing and running tests Graphical and textual test runners

  6. Limitations Impossible to test a client/server environment, or even a peer-to-peer scenario. We cannot perform distributed tests, so you don’t have a way to run the same series of tests simultaneously on several JVMs each running on different Operating Systems.

  7. A Quick Demo!!

  8. Setup and Teardown • Setup: • Use the @Before annotation on a method containing code to run before each test case. • Teardown: • Use the @After annotation on a method containing code to run after each test case. • These methods will run even if exceptions are thrown in the test case or an assertion fails. • It is allowed to have any number of these annotations. • All methods annotated with @Before will be run before each test case, but they may be run in any order.

  9. Example: Using a file as a text fixture public class OutputTest { private File output; @Before public void createOutputFile() { output = new File(...); } @After public void deleteOutputFile() { output.delete(); } @Test public void test1WithFile() { // code for test case objective } @Test public void test2WithFile() { // code for test case objective } }

  10. Method execution order • createOutputFile() • test1WithFile() • deleteOutputFile() • createOutputFile() • test2WithFile() • deleteOutputFile() • Assumption: test1WithFile runs before test2WithFile.

  11. Adding Tests to TestCases • Any method in a TestCase class is considered a test if it begins with the word test • You can write many tests (have many test methods) • Each test method should use a variety of assert methods to test things about the state of their classes under tests • Assert methods are inherited

  12. Assert Methods • Assert methods include: • assertEqual(x,y) • assertFalse(boolean) • assertTrue(boolean) • assertNull(object) • assertNotNull(object) • assetSame(firstObject, secondObject) • assertNotSame(firstObject, secondObject)

  13. Adding Two Tests to TestCase package testing; importjunit.framework.TestCase; publicclassFirstTestCaseextendsTestCase { publicFirstTestCase(String arg0) { super(arg0); } publicstaticvoid main(String[] args) {} protectedvoidsetUp() throws Exception { super.setUp(); } protectedvoidtearDown() throws Exception { super.tearDown(); } publicvoidtestCompareSucceed() { assertEquals(0, 0); //this assertion will succeed } publicvoidtestCompareFail() { assertEquals(0, 1); //this assertion will fail } }

  14. Sources https://staff.ti.bfh.ch/fileadmin/home/due1/uml_dp/JUnitTutorial-Williams-adapted.pdf http://vishnuagrawal.wordpress.com/2007/04/30/limitation-of-junit/ http://en.wikipedia.org/wiki/JUnit http://www.junit.org/

  15. Questions ?

More Related