《软件测试技术》课程第二周随笔
生活随笔
收集整理的這篇文章主要介紹了
《软件测试技术》课程第二周随笔
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這次的博客內容為,舉例解釋等價類劃分。
?
1. 問題描述
EditBox
在文本輸入框內輸入文字,然后按確認鍵。
允許接收的文字為:1至6個英文字符或數字。
?
2.等價類劃分
| ? | 有效等價類 | 編號 | 無效等價類 | 編號 |
| 包括的字符 | a-z,A-Z,0-9 | 1 | 其他字符 | 3 |
| 字符串長度 | 1-6 | 2 | 0 | 4 |
| ? | ? | ? | 大于6 | 5 |
?
3.測試用例
| 編號 | 輸入 | 覆蓋等價類 | 預期輸出 |
| Test1 | a | 1,2 | Accepted |
| Test2 | A | 1,2 | Accepted |
| Test3 | 0 | 1,2 | Accepted |
| Test4 | abAB01 | 1,2 | Accepted |
| Test5 | ? | 4 | Please try again. |
| Test6 | abcdefg | 5 | Please try again. |
| Test7 | @ | 3 | Please try again. |
| Test8 | a b | 3 | Please try again. |
| Test9 | ab_cd | 3 | Please try again. |
?
4.代碼實現及結果樣例
使用C#編寫,具體代碼如下。
這是C#自動生成的,描述GUI的Form1.Designer.cs的代碼:
namespace csharptest {partial class Form1{/// <summary>/// 必需的設計器變量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的資源。/// </summary>/// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗體設計器生成的代碼/// <summary>/// 設計器支持所需的方法 - 不要/// 使用代碼編輯器修改此方法的內容。/// </summary>private void InitializeComponent(){this.textBox1 = new System.Windows.Forms.TextBox();this.label1 = new System.Windows.Forms.Label();this.button1 = new System.Windows.Forms.Button();this.SuspendLayout();// // textBox1// this.textBox1.Location = new System.Drawing.Point(24, 49);this.textBox1.Name = "textBox1";this.textBox1.Size = new System.Drawing.Size(185, 21);this.textBox1.TabIndex = 0;// // label1// this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(51, 19);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(131, 12);this.label1.TabIndex = 1;this.label1.Text = "請輸入0~6個字母或數字";// // button1// this.button1.Location = new System.Drawing.Point(72, 85);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(75, 23);this.button1.TabIndex = 2;this.button1.Text = "確認";this.button1.UseVisualStyleBackColor = true;this.button1.Click += new System.EventHandler(this.button1_Click);// // Form1// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(227, 124);this.Controls.Add(this.button1);this.Controls.Add(this.label1);this.Controls.Add(this.textBox1);this.Name = "Form1";this.Text = "EditBox";this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.Label label1;private System.Windows.Forms.Button button1;} }這是其他代碼,有關于判斷字符串是否合法的部分,文件名為Form1.cs:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace csharptest {public partial class Form1 : Form{public Form1(){InitializeComponent();}private bool check(String text){if (text.Length <= 0) return false;if (text.Length > 6) return false;for (int i = 0; i < text.Length; i++){char c = text[i];if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9'))return false;}return true;}private void button1_Click(object sender, EventArgs e){if (check(textBox1.Text))MessageBox.Show("Accepted");elseMessageBox.Show("Please try again.");}} }測試用例結果圖:
| 測試編號 | EditBox | 返回結果 |
| Test1 | ||
| Test2 | ||
| Test3 | ||
| Test4 | ||
| Test5 | ||
| Test6 | ||
| Test7 | ||
| Test8 | ||
| Test9 |
?
?
轉載于:https://www.cnblogs.com/jinzhao1994/p/4357851.html
總結
以上是生活随笔為你收集整理的《软件测试技术》课程第二周随笔的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何分析网站日志文件
- 下一篇: 【转载】网易将军令工作原理