.net测试学习--理解.net测试选项
1.创建基于测试简单应用程序
(1)启动visual studio(有安装c#的)
(2) 选择File|New project
(3)创建一个C# project,名字和保存路径自己设定,假设取名test1
(4)添加一个text控件和button控件
设置属性如下:
对象 | 属性 | value |
Button1 | Test | check |
TextBox1 | Text | 空白 |
此时窗口如下:
(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;
此时代码结构如下:
(7)编译,debugging 或者使用F5
如果没有错误,此时应该如下
(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
如图:
(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");
}
}
此时整体代码如下:
(3)运行 程序F5或者使用Debug
转载请注明出处:http://www.cnblogs.com/tobecrazy/

软件测试交流QQ群:312937087 we are QA!
分类:
测试
标签:
.net 测试 vs
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?