Tuesday, December 15, 2009

Thursday, June 11, 2009

JUnit on myeclipse


JUnit on myeclipse

by Satya Siripuram





What is Junit


JUnit is a simple open source Java testing framework used to write and run repeatable automated

tests. It is an instance of the xUnit architecture for unit testing framework. Eclipse supports

creating test cases and running test suites, so it is easy to use for your Java applications.

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


What is a test case


A test case is a class which holds a number of test methods. For example if you want to test some

methods of a class AddClass you create a class AddClassTest which extends the JUnit TestCase class and place your test methods in there.




Working with Junit on myeclipse:


Step 1: select Window → Show View → Other → Java → select Junit → Ok


Just beside Package Explorer tree you could find JUnit view.



Example application:


1. Create a project :

a. go to File → New → Other → Java Project

b. name the project as TestingJUnitFinish

    1. Create a simple class:

a. right click on the project TestingJUnit goto New → Class

b. give package name as test.junit, class name as AddClass → Finish


AddClass.java


package test.junit;

public class AddClass {

public int add(int c ,int d)

{

return c+d;

}

}


3. Adding junit.jar to the project:

a. right click on the project → Properties → Java Build Path → select Libraries tab → Add External Jars → select the junit.jar → Ok


Note: download junit.jar here http://sourceforge.net/project/showfiles.php?group_id=15278&package_id=12472


  1. Creating test cases :

a. right click on the project TestingJUnit → New → Other → select Junit from the tree → Junit Test Case

b. give the package name as test.junit , class name as AddClassTest → only check setUP().

c. click on Browse for Class Under Select and type the name of the class that you want to test , here AddClass → Finish

d. add the following line of code inside testAdd()


assertEquals(13, ac.add(6, 7));


13 is the expected value.

ac.add(6,7) is the actual value



AddClassTest.java


package test.junit;


import junit.framework.TestCase;


public class AddClassTest extends TestCase {

private AddClass ac;


protected void setUp() throws Exception {

ac = new AddClass();

}


public void testAdd() {


assertEquals(13, ac.add(6, 7));


}


}


5. Running the Test Cases :

a. Right click on the project TestingJUnit → Run As → JUnit test





on Junit view you could see the following.




for testing give some different value like


assertEquals(12, ac.add(6, 7));


and Run again now you could see the following.






This is how you can test your application.


References:


http://www.scribd.com/doc/18134/Eclipse-tutorial-part-10-Using-JUnit-in-Eclipse


thanks and please send your comments to sat4java@gmail.com



Bookmark this pageDigg this sitesimpyslashdot

Tuesday, February 24, 2009

mysql bug : java.sql.SQLException: Unknown prepared statement handler (1) given to mysql_stmt_execute

In a situation where there are two servers, and C/J is setup for load balancing andfailover between them, there is a chance a server could crash due to invalid preparedstatements, or valid statements bug invalid parameters being sent.

Refer this link HERE

The party's over

I dont know how it works:(

Wednesday, February 11, 2009

java code to get the current date, month, year

java code to get the current date, month, year
 
java.util.Calendar cal = new java.util.GregorianCalendar();
 
System.out.println("Current Date : "+cal.get( Calendar.DATE ));
System.out.println("Current MONTH : "+cal.get( Calendar.MONTH ));
System.out.println("Current YEAR : "+cal.get( Calendar.YEAR ));

Sunday, February 8, 2009

mysql problem : Unauthenticated Users

Bug #8945 unauthenticated user and server crash
 
 
Posted by: KimSeong Loh ()
Date: December 13, 2008 06:15AM

Probably your DNS settings.
MySQL server tries to contact the DNS for each connection to perform reverse DNS before it can authenticate the user, so if this takes a long time due to DNS issue, the users will stuck in the unauthenticated state for a longer period of time.
 

Sunday, February 1, 2009

FW: Action Class Design Guidelines -Write code for a multi-threaded environment

 
-----Original Message-----
From: Satya Siripuram [mailto:satya.siripuram@sarkinfotech.com]
Sent: Monday, February 02, 2009 11:45 AM
To: 'sat4java.books4java@blogger.com'
Subject: Action Class Design Guidelines -Write code for a multi-threaded environment

 
This resource is really useful for those who want develop and work in multi-threaded environment see this section : 4.4.1 Action Class Design Guidelines