Junit Tutorial

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

J Unit tutorial for testing in java se process. This is a plugin of java.

Text of Junit Tutorial

  • 5/24/2018 Junit Tutorial

    1/59

    JUnit Tutorial

  • 5/24/2018 Junit Tutorial

    2/59

    i

    JUNIT TUTORIAL

    Simply Easy Learning by tutorialspoint.com

    tutorialspoint.com

  • 5/24/2018 Junit Tutorial

    3/59

    ii

    ABOUT THE TUTORIAL

    JUnit TutorialJUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks collectively known as xUnit that originated with JUnit.

    This tutorial will teach you how to use JUnit in your day-2-day life of any project unit testing while working with Javaprogramming language.

    Audience

    This tutorial has been prepared for the beginners to help them understand basic functionality of JUnit tool. After completingthis tutorial you will find yourself at a moderate level of expertise in using JUnit testing framework from where you can takeyourself to next levels.

    PrerequisitesWe assume you are going to use JUnit to handle all levels of Java projects development. So it will be good if you haveknowledge of software development using any programming language specially Java programming and software testingprocess.

    Copyright & Disclaimer Notice

    All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content fromtutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without thewritten permission of tutorialspoint.com. Failure to do so is a violation of copyright laws.

    This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy ofthe site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorialcontent contains some errors, please contact us atwebmaster@tutorialspoint.com

    http://c/Users/ZARA/Desktop/webmaster@tutorialspoint.comhttp://c/Users/ZARA/Desktop/webmaster@tutorialspoint.com
  • 5/24/2018 Junit Tutorial

    4/59

    iii

    Table of Contents

    JUnit Tutorial............................................................................. iAudience................................................................................... iPrerequisites............................................................................. iCopyright & Disclaimer Notice................................................... iJUnit Overview ...........................................................................What is JUnit ?...............................................................................................

    Features........................................................................................................What is a Unit Test Case ?...............................................................................

    JUnit Environment Setup ............................................................System Requirement......................................................................................

    Step 1 - verify Java installation in your machine.................................................

    Step 2: Set JAVA environment.........................................................................

    Step 3: Download Junit archive........................................................................

    Step 4: Set JUnit environment.........................................................................

    Step 5: Set CLASSPATH variable.......................................................................

    Step 6: Test JUnit Setup..................................................................................

    Step 7: Verify the Result..................................................................................

    JUnit Test Framework ................................................................Features........................................................................................................

    Fixtures.........................................................................................................

    Test suite.......................................................................................................

    Test runner....................................................................................................

    JUnit classes..................................................................................................

    JUnit Basic Usage ......................................................................Create a Class................................................................................................

    Create Test Case Class....................................................................................Create Test Runner Class.................................................................................

    JUnit API ....................................................................................Assert Class...................................................................................................

    TestCase Class................................................................................................

    TestResult Class.............................................................................................

    TestSuite Class...............................................................................................

  • 5/24/2018 Junit Tutorial

    5/59

    iii

    JUnit Writing Tests .....................................................................JUnit Using Assertion .................................................................Annotation....................................................................................................

    JUnit Execution Procedure .........................................................JUnit Executing Tests .................................................................Create a Class................................................................................................

    Create Test Case Class....................................................................................

    Create Test Runner Class.................................................................................

    JUnit Test Suite ..........................................................................Create a Class................................................................................................

    Create Test Case Classes.................................................................................

    Create Test Suite Class....................................................................................

    Create Test Runner Class.................................................................................

    JUnit Ignore Test ........................................................................Create a Class................................................................................................

    Create Test Case Class....................................................................................

    Create Test Runner Class.................................................................................

    JUnit Time Test ..........................................................................Create a Class................................................................................................

    Create Test Case Class....................................................................................

    Create Test Runner Class.................................................................................

    JUnit Exception Test ..................................................................

    Create a Class................................................................................................Create Test Case Class....................................................................................

    Create Test Runner Class.................................................................................

    JUnit Parameterized Test ...........................................................Create a Class................................................................................................

    Create Parameterized Test Case Class..............................................................

    Create Test Runner Class.................................................................................

    JUnit Plug with ANT ...................................................................Step 1: Download Apache Ant.........................................................................

    Step 2: Set Ant Environment............................................................................

    Step 3: Download Junit Archive.......................................................................Step 4: Create Project Structure.......................................................................

    Create ANT Build.xml......................................................................................

    JUnit Plug with Eclipse ...............................................................Step 1: Download Junit archive........................................................................

    Step 2: Set Eclipse environment.......................................................................

    Step 3: Verify Junit installation in Eclipse..........................................................

  • 5/24/2018 Junit Tutorial

    6/59

    iii

    JUnit Extensions ........................................................................Cactus......................................................................................................