软件测试之等价划分二

时间:2015-03-29 17:55:26   收藏:0   阅读:104

上周通过测试用例实现等价划分,这次需要三个输入框同时输入。其实只是增加了测试的次数。

这次我用java的程序测试。

首先是无输入:

技术分享

会提示你输入字符必须是1-6.

测试1:

字符一:

121221f

字符二:

jjhj12

字符三:

dsd1&&

测试结果如下:

技术分享

测试2:

字符一:

1212fd

字符二:

fdf123

字符三:

Adf2d1

测试结果:

技术分享

java代码如下:

package ceshi;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class softCeshi extends Application{
public static boolean isRegularRptCode(String rptCode,String regEx) {
Pattern pat = Pattern.compile(regEx);
Matcher mat = pat.matcher(rptCode);
boolean rs = mat.matches();
return rs;
}
public static void main(String[ ] args) {
softCeshi.launch( args );
}
public void start( Stage Stage ) {
Stage.setTitle( "软件测试用例" );
final AnchorPane anchorPane = new AnchorPane();
Stage.setScene(new Scene(anchorPane, 400, 400));

Text test1= new Text("字符一");
Text test2= new Text("字符二");
Text test3= new Text("字符三");

final TextField []text = new TextField[3];

text[0] = new TextField();
text[1] = new TextField();
text[2] = new TextField();

Button btn = new Button( );
btn.setText("提交");

AnchorPane.setTopAnchor(test1, 50.0);
AnchorPane.setLeftAnchor(test1, 60.0);

AnchorPane.setTopAnchor(test2, 100.0);
AnchorPane.setLeftAnchor(test2, 60.0);

AnchorPane.setTopAnchor(test3, 150.0);
AnchorPane.setLeftAnchor(test3, 60.0);

AnchorPane.setTopAnchor(text[0], 50.0);
AnchorPane.setLeftAnchor(text[0], 120.0);

AnchorPane.setTopAnchor(text[1], 100.0);
AnchorPane.setLeftAnchor(text[1], 120.0);

AnchorPane.setTopAnchor(text[2], 150.0);
AnchorPane.setLeftAnchor(text[2], 120.0);

AnchorPane.setTopAnchor(btn, 150.0);
AnchorPane.setLeftAnchor(btn, 300.0);

btn.setOnAction( new EventHandler<ActionEvent>( ) {
public void handle(ActionEvent actEvt) {
final String []test = new String[3];
for(int i=0;i<3;i++){
test[i] = text[i].getText();
if(test[i].length()<1||test[i].length()>6){
TextField text1 = new TextField("输入长度应为1-6");
AnchorPane.setTopAnchor(text1, 200.0+i*50);
AnchorPane.setLeftAnchor(text1, 120.0);
anchorPane.getChildren().add(text1);
}
else if(!isRegularRptCode(test[i],"[a-z,A-Z,0-9]*")){
TextField text2 = new TextField("输入字符应为a-z,A-Z,0-9");
AnchorPane.setTopAnchor(text2, 200.0+i*50);
AnchorPane.setLeftAnchor(text2, 120.0);
anchorPane.getChildren().add(text2);

}
else{
TextField text3 = new TextField("输入正确");
AnchorPane.setTopAnchor(text3, 200.0+i*50);
AnchorPane.setLeftAnchor(text3, 120.0);
anchorPane.getChildren().add(text3);
}
}
}} );

anchorPane.getChildren().addAll(btn,test1,test2,test3,text[0],text[1],text[2]);
Stage.show( );
}
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!