標籤:
一、問題介紹
上次編寫的問題,即有一個頁面,輸入1-6個英文字元或數字,已完成測試,測試案例的設計也得到練習,這次便讓問題複雜一些,改為有3個輸入框,因為問題規模增加了,所以,測試也就自然而然的變得複雜了。由於上次練習的是按照輸入進行測試,所以,這次練習按照輸出進行測試。
二、測試案例
| |
一行 |
二行 |
三行 |
預期結果 |
| test1 |
123 |
abc |
ABC |
ok |
| test2 |
|
abc |
ABC |
第一行字元數太少 |
| test3 |
njzdnbnbz |
abc |
ABC |
第一行字元數太多 |
| test4 |
、gr |
abc |
ABC |
第一行字元不合規範 |
| test5 |
123 |
|
ABC |
第二行字元數太少 |
| test6 |
123 |
njzdnbnbz |
ABC |
第二行字元數太多 |
| test7 |
123 |
\adfg |
ABC |
第二行字元不合規範 |
| test8 |
123 |
abc |
|
第三行字元數太少 |
| test9 |
123 |
abc |
sgzngrfsn |
第三行字元數太多 |
| test10 |
123 |
abc |
v%g |
第三行字元不合規範 |
三、測試過程
這是首頁
test1結果
test2結果
test3結果
test4結果
test5結果
test6結果
test7結果
test8結果
test9結果
test10結果
此次測試結果如所示,結果證明軟體符合要求。
三、代碼
<%@ page import = "java.io.*"%><%@ page import = "java.util.*"%><%@ page import = "java.sql.*"%><%@ page import = "javax.sql.*"%><%@ page import = "javax.naming.*"%><%@ page contentType = "text/html; charset=utf-8"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%request.setCharacterEncoding("utf-8"); %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head><title>首頁</title> </head> <body> <center> <form action="yanzheng.jsp" method="post"> <fieldset style="width:400px;height:150px"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td width = "20%" align = "center">name1:</td> <td><input type="text" name="name1" size=‘45‘></td> </tr> <br/> <tr> <td width = "20%" align = "center">name2:</td> <td><input type="text" name="name2" size=‘45‘></td> </tr> <br/> <tr> <td width = "20%" align = "center">name3:</td> <td><input type="text" name="name3" size=‘45‘></td> </tr> <br/> <tr> <td colspan="2" align = "center"><input type="submit" name="submit" value="提交"> </td> </tr> </table> </fieldset> </form> </center> </body> </html>
<%@ page import = "java.io.*"%><%@ page import = "java.util.*"%><%@ page import = "java.sql.*"%><%@ page import = "javax.sql.*"%><%@ page import = "javax.naming.*"%><%@ page contentType = "text/html; charset=utf-8"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><%request.setCharacterEncoding("utf-8"); %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>驗證</title> </head> <body> <% try{ String a = request.getParameter("name1"); String b = request.getParameter("name2"); String c = request.getParameter("name3"); int num1 = a.length(); int num2 = b.length(); int num3 = c.length(); boolean bool1 = true; boolean bool2 = true; boolean bool3 = true; if(num1==0){ bool1 = false; %> <center> <table> <tr><td>第一行字元數太少,請返回修改</td></tr> <tr><td> </center> <% } else if(num1>6){ bool1 = false; %> <center> <table> <tr><td>第一行字元數太多,請返回修改</td></tr> <tr><td> </center> <%} else{ char ch; for(int i = 0;i < num1;i++){ ch = a.charAt(i); int n =(int)(ch); if((n>47&&n<58)||(n>64&&n<91)||(n>96&&n<123)){} else{ bool1 = false; break; } } if(bool1){} else{ %> <center> <table> <tr><td>第一行字元不合規範,請返回修改</td></tr> <tr><td> </center> <% } } if(num2==0){ bool2 = false; %> <center> <table> <tr><td>第二行字元數太少,請返回修改</td></tr> <tr><td> </center> <% } else if(num2>6){ bool2 = false; %> <center> <table> <tr><td>第二行字元數太多,請返回修改</td></tr> <tr><td> </center> <%} else{ char ch; for(int i = 0;i < num2;i++){ ch = b.charAt(i); int n =(int)(ch); if((n>47&&n<58)||(n>64&&n<91)||(n>96&&n<123)){} else{ bool2 = false; break; } } if(bool2){} else{ %> <center> <table> <tr><td>第二行字元不合規範,請返回修改</td></tr> <tr><td> </center> <% } } if(num3==0){ bool3 = false; %> <center> <table> <tr><td>第三行字元數太少,請返回修改</td></tr> <tr><td> </center> <% } else if(num3>6){ bool3 = false; %> <center> <table> <tr><td>第三行字元數太多,請返回修改</td></tr> <tr><td> </center> <%} else{ char ch; for(int i = 0;i < num3;i++){ ch = c.charAt(i); int n =(int)(ch); if((n>47&&n<58)||(n>64&&n<91)||(n>96&&n<123)){} else{ bool3 = false; break; } } if(bool3){} else{ %> <center> <table> <tr><td>第三行字元不合規範,請返回修改</td></tr> <tr><td> </center> <% } } if(bool1 && bool2 && bool3){ %> <center> <table> <tr><td>ok</td></tr> <tr><td> <a href = "<%=request.getContextPath()%>/index.jsp">返回</a> </td></tr> </table> </center> <% } else{ %> <center> <table> <tr><td> <a href = "<%=request.getContextPath()%>/index.jsp">返回</a> </td></tr> </table> </center> <% } }catch(Exception e){out.println(e.getMessage());} %> </body></html>
測試案例練習2