Java上等價類別劃分測試的實現

來源:互聯網
上載者:User

標籤:

利用JavaFx實現對有效等價類別和無效等價類別的劃分:

 

代碼:

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.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Main extends Application{
TextField textField;
Label label;

public static void main(String[] args) {
Application.launch(args);
}

public void start(Stage stage){
stage.setTitle("For Test");
AnchorPane root = new AnchorPane();
Scene scene = new Scene(root, 500, 300);

Text text = new Text();
text.setText("Write something for test:");
text.setFont(Font.font("Comic Sans MS", 18));
AnchorPane.setTopAnchor(text, 0.0);
AnchorPane.setLeftAnchor(text, 10.0);

Text text2 = new Text();
text2.setText("Result:");
text2.setFont(Font.font("Comic Sans MS", 18));
AnchorPane.setTopAnchor(text2, 50.0);
AnchorPane.setLeftAnchor(text2, 10.0);

label = new Label(" ");
label.setFont(Font.font ("Comic Sans MS", 16));
AnchorPane.setTopAnchor(label, 90.0);
AnchorPane.setLeftAnchor(label, 50.0);

Button button = new Button();
button.setText(" Sure ");
AnchorPane.setTopAnchor(button, 5.0);
AnchorPane.setLeftAnchor(button, 420.0);

textField = new TextField ();
textField.setPrefWidth(160);
textField.getText();
AnchorPane.setTopAnchor(textField, 5.0);
AnchorPane.setLeftAnchor(textField, 250.0);

button.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent e) {
char input[] = textField.getText().toCharArray();
int errorcase = 3;
if (textField.getText().length()==0 || textField.getText().length() >= 7) {
errorcase = 1;
}
else {
for(int i=0;i<textField.getText().length();i++){
if(!((input[i]>=48 && input[i]<57) || (input[i]>=65 && input[i]<=90) || (input[i]>=97 && input[i]<=122))){
errorcase = 2;
break;
}
}
}
switch(errorcase){

case 1:
label.setText("Input is " + textField.getText() + "\n" + "Error1: The length of input is error");
break;

case 2:
label.setText("Input is " + textField.getText() + "\n" + "Error2: The kind of input is error");
break;

case 3:
label.setText("Input is " + textField.getText() + "\n" + "Succeed: Input is correct");

}
}
});

root.getChildren().addAll(text,text2,textField,button,label);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
}

等價類別劃分和測試案例設計:


編號1、2、3、8、11、17的測試:

 

Java上等價類別劃分測試的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.