日期:2014-05-20  浏览次数:20815 次

Junit如何对静态代码块进行测试
有一个静态代码块如下:
Java code

public class JdbcUtil {

    private final static String databaseUrl = "jdbc:mysql://localhost:3306/";
    private final static String databaseName = "jdbc";
    private final static String databaseUser = "root";
    private final static String databasePwd = "root";
    private final static String driverName = "com.mysql.jdbc.Driver";
    private final static String driverRegex = "/^[A-Za-z](/.)[A-Za-z](/.)[A-Za-z](/.)[A-Za-z]$/";
    
    static {
        try {
            Pattern p = Pattern.compile(driverRegex);
            Matcher m = p.matcher(driverName);
            System.out.println("是否匹配" + m.matches());
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}



要对static 中的内容进行测试,在JUNIT中应该如何操作?
急。在线等高手指教。

------解决方案--------------------
百度一下,你就知道