测试用例练习2

一、问题介绍

  上次编写的问题,即有一个页面,输入1-6个英文字符或数字,已完成测试,测试用例的设计也得到练习,这次便让问题复杂一些,改为有3个输入框,因为问题规模增加了,所以,测试也就自然而然的变得复杂了。由于上次练习的是按照输入进行测试,所以,这次练习按照输出进行测试。

二、测试用例

 一行二行三行预期结果
test1123abcABCok
test2 abcABC第一行字符数太少
test3njzdnbnbzabcABC第一行字符数太多
test4、grabcABC第一行字符不合规范
test5123 ABC第二行字符数太少
test6123njzdnbnbzABC第二行字符数太多
test7123\adfgABC第二行字符不合规范
test8123abc 第三行字符数太少
test9123abcsgzngrfsn第三行字符数太多
test10123abcv%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>

 

转载于:https://www.cnblogs.com/tiandaliang/p/4375532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值