JUnit implementation Process

Source: Internet
Author: User
Tags mysql stmt

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.