第二章 理解.NET测试选项
2.1用于测试的.NET命名空间
测试人员必须完成的一个重要的工作是,查找并返回如下信息:应用程序在运行时的信息、系统在运行应用程序之前、之后和运行过程中的状态信息。要想学习如何获取重要的系统信息,首先要理解如何使用.NET命名空间。
用于测试的一些重要的命名空间有下面几个:
System.IO
System.Data
System.Text.ReguarExpressions
Microsoft.Win32
System.Web
Microsoft.VisuaStudio.TestToos
Microsoft.VisuaBasic
System.Diagnostics
在后面将作详细解释。
打开Visua Studio.NET从View->Object Browser中可以看到一些命名空间,以及包含用于测试的例程。
2.2使用System.IO命名空间中的Exists函数
Exists可以判断文件是否存在。被测的应用程序在运行期间常常会创建文件,包括永久文件和临时文件,因此可以用Exists函数来确定应用程序运行时是否创建或删除了适当的文件。
例:
using System;
using System.Coections.Generic;
using System.ComponentMode;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace firsttest
{
pubic partia cass Form1 : Form
{
pubic Form1()
{
InitiaizeComponent();
}
private void button1_Cick(object sender, EventArgs e)
{
if (Fie.Exists(textBox1.Text))
MessageBox.Show("Fie Exists:Test passed");
ese
MessageBox.Show("Fie doesn't Exists:Test faiure");
}
}
}