您的位置:首页 > 其它

软件测试(3)-基于等价类划分的一个小例子

2015-03-29 17:40 387 查看
程序要求从一个输入框变为3个输入框,其他要求不变

则这次的测试用例本着等价类划分的原则进行如下的修改

表格旁边的就此这次的测试代码

box No.1

box No.2box No.3Result
abcabcabcsuccess
abcabcbox No.1 fail
abcabcbox No.2 fail
abcabcbox No.3 fail
*1abcdefghAll Fail
abc*11bcedfgrtOnly box No.1 success
*7abcOnly box No.2 success
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 Test extends Application{

public static void main(String arg0[]){
Test.launch(arg0);
}

public void start(Stage stage) throws Exception {
stage.setTitle("Test One");
AnchorPane root = new AnchorPane();

Text text = new Text("请输入:");
root.getChildren().add(text);
AnchorPane.setTopAnchor(text, 45.0);
AnchorPane.setLeftAnchor(text, 100.0);

final TextField textInput1 = new TextField();
root.getChildren().add(textInput1);
AnchorPane.setTopAnchor(textInput1, 65.0);
AnchorPane.setLeftAnchor(textInput1, 30.0);

final TextField textInput2 = new TextField();
root.getChildren().add(textInput2);
AnchorPane.setTopAnchor(textInput2, 95.0);
AnchorPane.setLeftAnchor(textInput2, 30.0);

final TextField textInput3 = new TextField();
root.getChildren().add(textInput3);
AnchorPane.setTopAnchor(textInput3, 125.0);
AnchorPane.setLeftAnchor(textInput3, 30.0);

Button button = new Button();
button.setText("确定");
root.getChildren().add(button);
AnchorPane.setTopAnchor(submit, 165.0);
AnchorPane.setLeftAnchor(submit, 75.0);

submit.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent arg0) {
if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString()) && checkString(textInput3.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("三个输入框均符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("第三个输入框不符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput1.getText().toString()) && checkString(textInput3.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("第二个输入框不符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput2.getText().toString()) && checkString(textInput2.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("第一个输入框不符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput1.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("只有第一个输入框符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput2.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("只有第二个输入框符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else if(checkString(textInput3.getText().toString())){
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("只有第三个输入框符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}else{
Stage stage2 = new Stage();
AnchorPane root2 = new AnchorPane();

Text result = new Text("三个输入框均不符合要求~");
root2.getChildren().add(result);
AnchorPane.setTopAnchor(result, 50.0);
AnchorPane.setLeftAnchor(result, 50.0);

stage2.setScene(new Scene(root2, 100, 100));
stage2.show();
}
}
});

stage.setScene(new Scene(root, 190,225));
stage.show();
}

public boolean checkString(String str){
if(str.length() == 0 || str.length() >= 7){
return false;
}

char ch[] = new char[str.length()];
ch = str.toCharArray();

for(int i = 0; i < str.length(); i++){
if((ch[i] >= 'a' && ch[i] <= 'z')||(ch[i] >= 'A' && ch[i] <= 'Z')||(ch[i] >= '0' && ch[i] <= '9'));
else{
return false;
}
}
return true;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: