软件测试(3)-基于等价类划分的一个小例子
2015-03-29 17:40
387 查看
程序要求从一个输入框变为3个输入框,其他要求不变
则这次的测试用例本着等价类划分的原则进行如下的修改
表格旁边的就此这次的测试代码
则这次的测试用例本着等价类划分的原则进行如下的修改
表格旁边的就此这次的测试代码
box No.1 | box No.2 | box No.3 | Result |
abc | abc | abc | success |
abc | abc | box No.1 fail | |
abc | abc | box No.2 fail | |
abc | abc | box No.3 fail | |
*1 | abcdefgh | All Fail | |
abc | *1 | 1bcedfgrt | Only box No.1 success |
*7 | abc | Only 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; } }
相关文章推荐
- 关于二级指针的使用测试小例子,仅供测试--参数传递的时候用指针最好,因为压栈的时候指针,只是压入一个地址的值,最多4个字节(32位机上),提供的3个测试例子,基于VC6.0的环境。
- java中的基于套结字(socket)的通信 一. 一个双人单方向通信例子
- 一个基于jabber 的IM通信息软件.开放源代码
- 一个软件测试工程师20年的地位浮沉
- 软件开发中的矛盾——一个简单的例子
- 图形编辑软件的副产品:一个基于VS2005的建模工具
- 一个cactus测试的例子,用eclipse
- 软件开发中的矛盾——一个简单的例子
- 一个活动对象的测试例子
- 基于模块化设计的嵌入式软件测试方法
- 一个基于三层架构的例子
- 应用 Rational 工具简化基于 J2EE 的项目第 8 部分 :测试软件
- 转载:一个软件测试工程师05年工作总结
- 一个软件测试人员的经验分享
- 这是一个测试的例子
- 应用 Rational 工具简化基于 J2EE 的项目第 8 部分 :测试软件
- Tangram:一个基于MFC框架的柔性软件开发系统
- 一个测试接口加载,类加载很好的例子
- 一个有趣的反病毒软件测试
- 一个软件测试工程师的加班经历