JUnit

abusivefroggerySoftware and s/w Development

Nov 16, 2012 (4 years and 10 months ago)

302 views

Rohan

Ramekar

CSE
-

5324


What is
JUnit
?


Why use it?


How to use it?


Sample test case



Java’s standard unit testing framework.


Developed by Erich Gamma and Kent
Beck.


Many IDEs like Eclipse,
Netbeans
,
Jbuilder

come equipped with
JUnit
.


JUnit.org



Unit Testing



Small code snippet to test
classes or functions.


Test Cases



Written and run by software
developers.


Intention

-


To ensure that code meets its
design and behaves as intended.


JUnit

is used to write and run repeatable
automated tests.


A
unit test

is a test of a
single

class


A
test case

tests the response of a single
method to a particular set of inputs


A
test suite
is a collection of test cases


A
test runner
is software that runs tests
and reports results


Generates the prototype of Test case.


A typical test



public class
MyClassTest



{

@Test





public void
testMethod
()




{





//Test to be performed





}




}


An assert method is a
JUnit

method that
performs a test, and throws an
AssertionFailedError

if the test fails


JUnit

catches these Errors and shows you the result


A typical assert method


assertEquals
(String
message
,
expected
,
actual
)



JUnit

helps the programmer:


define and execute tests and test suites


formalize requirements and clarify architecture


write and debug code



Junit.org


Tutorial
-

http://code.google.com/p/t2framework/
wiki/JUnitQuickTutorial