Test Categories: White box testing, black box testing, unit testing, integrated testing, functional testing .... A white box test is a test that knows how the software being tested is completed and what (What) functions are performed, typically by a developer, and unit tests are a white box test because developers know the software they write best. JUnit is a regression test framework written by Erich Gamma and Kent Beck, and regression testing is where you continually test the code you write (such as unit tests): write some, test some, debug some, and then loop through the process, and you'll repeat the previous tests, Even if you are writing other classes.
First step:
Go to the JUnit home page (http://www.junit.org) to download the latest version of the package. Unzip the package to C:\junit (customizable).
Step Two:
If the catalogue is C:\junit then, add in Classpath: "C:\junit\;c:\junit\junit.jar;" Defines the classpath of the class. Run at a command prompt: Java junit.swingui.TestRunner, if all is correct, the application will open. Look for examples of programs that are brought in from the Drop-down menu, such as: Junit.samples.AllTests, and click "Run" to see the results.
Step Three:
To implement your own test plan, there is currently a database operation class called Mybean that needs to be tested as follows:
Package junit.samples
Import java.sql.*;
import java.io.*;
public class mybean{
Statement stmt =null;
ResultSet Rs=null;
Connection Conn=null;
String Result=null;
Public String con () {//Initialize database
try{
Class.forName ("Org.gjt.mm.mysql.Driver"). Newinstance ()
String url = "jdbc:mysql://192.168.0.88/weboa?user=root&password=";
conn= drivermanager.getconnection (URL);
Return "Connection success!";
}
catch (Exception e) {
System.out.println (e);
return "Connection error!";
}
}
Public String gogo (string lmdm) {//Query database
try{
stmt=conn.createstatement ();
String sql= "SELECT * from TB_LM where n_lmdm= '" +lmdm+ "";
Rs=stmt.executequery (SQL);//Execute Query
while (Rs.next ()) {
Result=rs.getstring ("N_sjid");
}
}
catch (Exception e) {
result=e.tostring ();
}
Finally {//shutdown JDBC Resource
if (Rs!= null) try {rs.close ();} catch (SQLException ex) {ex.printstacktrace ();}
if (conn!= nulL) try {conn.close ();} catch (SQLException ex) {ex.printstacktrace ();}
}
return result;
}
}