Friday, December 30, 2011

JUNIT testing

JUNIT testing is a unit testing framework for java Programming Language. Which is one of the family of unit testing frameworks collectively known as xUnit and organized with sUnit.

Unit test = “Individual unit of Testing”.

xUnit : Various code-driven testing frameworks have come to be known collectively as xUnit. These frameworks allow testing of different elements (units) of software, such as functions and classes. The main advantage of xUnit frameworks is that they provide an automated solution with no need to write the same tests many times, and no need to remember what should be the result of each test.

Code Driven Testing : It checks the Expected output comes or not for all modules.

SUnit : SUnit is a unit testing framework for the programming language Smalltalk.

Small Talk : Smalltalk is an object-oriented, dynamically typed, reflective programming language.

JUnit Testing Example:

* Write Class for testing

* Testcase

* Test Suite

Example:

Class{

§public class TestClass {

public static int testfunction(int a,int b){

return(a+b); }

public static void main(String[] as){

TestClass1 obj=new TestClass1();

System.out.print(obj.testfunction(2,3));

}

}

Test case:

§Test case class should starts with test and should be the subclass testCase class.

public class TestClass1Test extends TestCase {

§

protected void setUp() throws Exception {

super.setUp();

}

protected void tearDown() throws Exception {

super.tearDown();

}

public void testTestfunction() {

int c=TestClass1.testfunction(5, 3);

assertEquals("Test Fails",8,c);

}

}

TestSuite:

§public class AllTests { §

public static Test suite() {

TestSuite suite = new TestSuite(AllTests.class.getName());

//$JUnit-BEGIN$

suite.addTestSuite(TestClass1Test.class);

//$JUnit-END$

return suite;

}

}

No comments:

Post a Comment