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