首页 技术 正文
技术 2022年11月20日
0 收藏 968 点赞 3,678 浏览 1472 个字

1.创建基于测试简单应用程序

(1)启动visual studio(有安装c#的)

  (2)  选择File|New project

 (3)创建一个C# project,名字和保存路径自己设定,假设取名test1

.net测试学习–理解.net测试选项

(4)添加一个text控件和button控件

设置属性如下:

对象 属性 value
Button1 Test check
TextBox1 Text 空白

此时窗口如下:

.net测试学习–理解.net测试选项

(5) 双击设计器中的check按钮(之前添加的Button1)

添加如下代码:

            if (textBox1.Text.Equals(""))          //if text is null  show message enter PATH
MessageBox.Show("Please enter your file PATH\n"); else // check if your file is exists {
if (File.Exists(textBox1.Text))
MessageBox.Show(textBox1.Text + "\tis exists\n");
else
MessageBox.Show(textBox1.Text + "\tisn't exists\n");
}

(6)在代码文件开头添加,不要忘记在结尾加分号

Using System.IO;

此时代码结构如下:

.net测试学习–理解.net测试选项

(7)编译,debugging 或者使用F5

如果没有错误,此时应该如下

.net测试学习–理解.net测试选项

(8) 测试

a.不输入  会提示:Please enter your file PATH

   b. 输入不存在的路径 比如aa 输出aa isn’t exists 反向测试

     c.输入c:\Windows\explorer.exe 输出 c:\Windows\explorer.exe is exists 正向测试

2.用控制台应用程序创建测试软件

控制台程序访问的三种基本数据流:标准输入,标准输出和标准错误

(1)创建工程 选择File|New Project,单击Console application,此时可以设置工程名字:test2

如图:

.net测试学习–理解.net测试选项

(2)添加代码

在开头添加 Using System.IO

在main函数内添加如下代码:

 Console.WriteLine("***************************************************");
Console.WriteLine("Enter the file PATH,Enter Q/q to quit\n");
Console.WriteLine("***************************************************");
string strInput = "";
while (!strInput.ToUpper().Equals("Q")) //only if enter Q/q then quit
{
strInput = Console.ReadLine(); //read the command line and put into strInput
Console.WriteLine("your file name is:"+ strInput);
if (File.Exists(strInput))
{
Console.WriteLine(strInput+" File Exists:Test PASS");
}
else
{
Console.WriteLine(strInput + " File doesn't Exists:Test FAIL");
Console.WriteLine("Enter the file PATH,Enter Q/q to quit\n");
}
}

此时整体代码如下:

.net测试学习–理解.net测试选项

(3)运行 程序F5或者使用Debug

.net测试学习–理解.net测试选项

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918