一、问题介绍
上次编写的问题,即有一个页面,输入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>