junit比这强多了,到时也给俺们讲讲!

解决方案 »

  1.   

    junit 也需要写测试类的,而且用junit写测试类也还是比较麻烦的。但是搂住说的通用到底能通用到那种程度呢?不通用的东西写起来麻烦,太通用的东西操作性不强。
      

  2.   

    junit 写测试类并不麻烦,很简单,你想一点不写测试代码就想测试一个程序,可能吗?通过写一个程序的测试类的好坏,就可以看出一个程序的真实水平与经验。用ant+junit
      

  3.   

    我用JSP表单中写调试代码写入模版SERVET中,然后用JSP调用JAVAC编译,然后再执行该SERVLET获取调试结果。
    但是我使用的RESIN服务器一旦JAVAC编译完成类改变整个APPLICATION就重启,所以效果不好
    package com.jingjian.tcmms;import com.jingjian.tcmms.*;
    import com.jingjian.tcmms.Util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;public class Debug  extends HttpServlet
    {
     static final private String CONTENT_TYPE = "text/html; charset=GBK";  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
        doPost(request,response);
      }
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {   response.setContentType(CONTENT_TYPE);    ////调试代码开始    System.out.println("hello world");    ////调试代码结束  }
    }
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page language="java" import="java.sql.*,java.util.*,java.io.*,com.jingjian.tcmms.*,com.jingjian.tcmms.Util.*" %>
    <%@include file="auth_include.jsp"%>
    <%
    String code="";
    code=request.getParameter("code");
    if(code==null) code="";%>
    <html>
    <head>
    <link rel=STYLESHEET type="text/css" href="../other/style.css">
    <html>
    <head>
    <title>
    调试
    </title>
    <script src="../js/common.js"></script>
    </head>
    <body>
    <form action=debug.jsp method=post>
    <center>
    调试JAVA代码:<br>
    <textarea name=code cols=80 rows=20><%=code%></textarea>
    <br>
    <input type=submit value="运行调试代码">
    </center>
    </form>
    <%
     if(code==null)   return;
     String filename=this.getServletContext().getRealPath("/WEB-INF/classes/com/jingjian/tcmms/")+"Debug.java";
     File file=new File(filename);
     if(!file.exists()) out.println("模板文件"+filename+"不存在!"); java.io.FileInputStream fis=new java.io.FileInputStream(file);
     byte[] c=new byte[(int)file.length()];
     fis.read(c);
     fis.close(); String content=new String(c,"GBK");
     int pos1=content.indexOf("////调试代码开始"),pos2=content.indexOf("////调试代码结束");
     if(pos1<0||pos2<0) {out.println("模板文件错误!");}
     else
     { pos1+="////调试代码开始".length();
       FileWriter fw=new FileWriter(file);
       fw.write(content.substring(0,pos1)+"\r\n\r\n");
       fw.write(code+"\r\n\r\n   ");
       fw.write(content.substring(pos2));
       fw.close();
     }  try
      {
        out.println("<hr>");
        Runtime r=Runtime.getRuntime();
        String classpath=getServletContext().getRealPath("/WEB-INF/classes")+";"+getServletContext().getRealPath("/WEB-INF/lib/servlet.jar");
        String cmd="javac -classpath "+classpath+" "+filename;
        System.out.println("编译调试指令:"+cmd);
        out.println("编译调试指令:"+cmd+"<br>");
        java.lang.Process p=r.exec(cmd);
        DataInputStream  dis=new java.io.DataInputStream(p.getInputStream());
        out.println("<h3><font color=blue>编译调试指令返回结果:</font></h3><pre>");
        byte buf[]=new byte[512];
        int readed=0;
        while((readed=dis.read(buf))>-1) out.print(Util.replace(new String(buf,0,readed,"GBK"),"<","&lt"));
        out.println("</pre>");
        out.println("<h3>成功编译调试指令。</h3>");   out.println("<h3><font color=blue>调试指令返回结果:</font></h3><pre>");
       out.println("<hr>");
       this.getServletContext().getRequestDispatcher("/servlet/com.jingjian.tcmms.Debug").include(request,response);
       out.println("<hr>");
      }
      catch(Exception e) {out.println("<h2>执行命令出错!</h2>");e.printStackTrace(new PrintWriter(out));e.printStackTrace();}%>
    </body>
    </html>
      

  4.   

    呵呵,楼主问的是struts的测试.看来懂StrutsTestCase的还不是很多啊
      

  5.   

    AllError(错误大全)有什么解决方案吗?
    单个的测试类我都会写,action类用StrutsTestCase,bean类用junit
    我觉得action类可以写通用的,不过这几天很忙没时间去做