net自动化测试之道API测试-自动运行测试套件
2011-08-15 22:46
399 查看
Launching a Test Harness Automatically
You want your test harness program tolaunch automatically.
Design
Use the Windows Task Scheduler.
Solution
You will often want to launch your testautomation automatically.For example you might
schedule a test automation harness to startat 2:00 A.M.so that it runs overnight,and the test
results are ready to review when you cometo work.The Windows Task Scheduler makes it easy
to schedule tasks in a Windows environment.You specify the test harness executable,the
scheduleof when you want the harness to run,and the security context under which youwant
theharness to run.
Ifyou have several lightweight test-automation harnesses that you want to run,youcan
createa.BAT file with commands to launch them.For example,
@echo off
echo Starting test automation sequence
echo.
C:\TestHarness1\bin\Debug\Run.exe
C:\TestHarness2\bin\Debug\Run.exe
C:\TestHarness3\bin\Debug\Run.exe
echo.
echo Test automation sequence complete
Ifyour harnesses explicitly log test case results to external files,then this isall you need.If
yourharnesses log test case results to the command shell,then you can easily savethem to
externalstorage using system redirection such as:
C:\TestHarness1\bin\Debug\Run.exe>C:\Results\Harness1Results.txt
C:\TestHarness2\bin\Debug\Run.exe>C:\Results\Harness2Results.txt
如果我们有若干个轻量级自动化测试套件要自动运行,我们可以创建一个.BAT命令文件。例如:
@echo off
echo Starting test automation sequence
echo.
C:\TestHarness1\bin\Debug\Run.exe
C:\TestHarness2\bin\Debug\Run.exe
C:\TestHarness3\bin\Debug\Run.exe
echo.
echo Test automation sequence complete
如果我们将测试用例结果显式地记录在外部文件,那么这种方式正是我们需要的,如果测试用例结果记录在命令行,那通过系统重定向可以很容易地将测试结果存储到外部文件中,如:
C:\TestHarness1\bin\Debug\Run.exe>C:\Results\Harness1Results.txt
C:\TestHarness2\bin\Debug\Run.exe>C:\Results\Harness2Results.txt
Comments
For most lightweight test-automation situations,using.BATfiles to manage multiple test har-
nesses is simple and effective.Analternative is to write a C#master harness that coordinates
and calls the worker automationharnesses.You can write statements that call the worker har-
nesses by using the static Start()method inthe System.Diagnostics.Process namespace:
Console.WriteLine("Startingtest automation sequence\n");
Process.Start("C:\\TestHarness1\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness2\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness3\\bin\\Debug\\Run.exe");
Console.WriteLine("\nTest automation sequence complete\n");
and then schedulethis one master program using the Task Scheduler.An advantage of using a
.BATfile master solution is simplicity.An advantage of using a C#master solution isthat you
haveincreased power to do things like catch exceptions and add branching logic toexecute a
workerharness only if a preceding harness test results meet some condition.
Insteadof using the Windows Task Scheduler to automatically launch a test harness,you
canuse the old at command.Scheduling a test harness or master harness program torun
usingthe at command is more difficult than using the Windows Task Scheduler.Youshould
onlyuse at if your test system does not support the Task Scheduler or if you areintegrating a
newtest harness system into an existing system that uses the at command.
Console.WriteLine("Starting testautomation sequence\n");
Process.Start("C:\\TestHarness1\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness2\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness3\\bin\\Debug\\Run.exe");
Console.WriteLine("\n Test automationsequence complete\n");
然后使用windows的任务计划计划该主程序的运行。使用.BAT的优点是简单。使用C#编写主程序实现的优点是当在前面调用的测试套件出现一些状况的时候,它更有能力处理如捕获异常、增加新的执行套件的逻辑分支等事件。
除了使用windows的任务计划让测试套件自动运行,我们也可以使用at命令来让测试套件或主测试套件程序自动运行。使用at命令要不使用windows任务计划要复杂。我们仅仅在测试系统不支持任务计划或者将新的测试套件系统整合到使用at命令的系统中的时候才用at命令。
自动运行测试套件
ProblemYou want your test harness program tolaunch automatically.
问题
如何让我们的测试套件自动运行呢?Design
Use the Windows Task Scheduler.
设计
利用windows的任务计划Solution
You will often want to launch your testautomation automatically.For example you might
schedule a test automation harness to startat 2:00 A.M.so that it runs overnight,and the test
results are ready to review when you cometo work.The Windows Task Scheduler makes it easy
to schedule tasks in a Windows environment.You specify the test harness executable,the
scheduleof when you want the harness to run,and the security context under which youwant
theharness to run.
Ifyou have several lightweight test-automation harnesses that you want to run,youcan
createa.BAT file with commands to launch them.For example,
@echo off
echo Starting test automation sequence
echo.
C:\TestHarness1\bin\Debug\Run.exe
C:\TestHarness2\bin\Debug\Run.exe
C:\TestHarness3\bin\Debug\Run.exe
echo.
echo Test automation sequence complete
Ifyour harnesses explicitly log test case results to external files,then this isall you need.If
yourharnesses log test case results to the command shell,then you can easily savethem to
externalstorage using system redirection such as:
C:\TestHarness1\bin\Debug\Run.exe>C:\Results\Harness1Results.txt
C:\TestHarness2\bin\Debug\Run.exe>C:\Results\Harness2Results.txt
解决方案
通常我们想让测试套件自动运行。例如,我们可能想让我们的测试套件在凌晨2:00运行,这样套件可以在晚上运行,第二当我们来上班的时候就可以检查测试结果。在windows环境中,windows的任务计划可以使自动运行测试套件很容易实现。我们详细说明可执行的测试套件、运行计划时间和运行的安全策略。如果我们有若干个轻量级自动化测试套件要自动运行,我们可以创建一个.BAT命令文件。例如:
@echo off
echo Starting test automation sequence
echo.
C:\TestHarness1\bin\Debug\Run.exe
C:\TestHarness2\bin\Debug\Run.exe
C:\TestHarness3\bin\Debug\Run.exe
echo.
echo Test automation sequence complete
如果我们将测试用例结果显式地记录在外部文件,那么这种方式正是我们需要的,如果测试用例结果记录在命令行,那通过系统重定向可以很容易地将测试结果存储到外部文件中,如:
C:\TestHarness1\bin\Debug\Run.exe>C:\Results\Harness1Results.txt
C:\TestHarness2\bin\Debug\Run.exe>C:\Results\Harness2Results.txt
Comments
For most lightweight test-automation situations,using.BATfiles to manage multiple test har-
nesses is simple and effective.Analternative is to write a C#master harness that coordinates
and calls the worker automationharnesses.You can write statements that call the worker har-
nesses by using the static Start()method inthe System.Diagnostics.Process namespace:
Console.WriteLine("Startingtest automation sequence\n");
Process.Start("C:\\TestHarness1\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness2\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness3\\bin\\Debug\\Run.exe");
Console.WriteLine("\nTest automation sequence complete\n");
and then schedulethis one master program using the Task Scheduler.An advantage of using a
.BATfile master solution is simplicity.An advantage of using a C#master solution isthat you
haveincreased power to do things like catch exceptions and add branching logic toexecute a
workerharness only if a preceding harness test results meet some condition.
Insteadof using the Windows Task Scheduler to automatically launch a test harness,you
canuse the old at command.Scheduling a test harness or master harness program torun
usingthe at command is more difficult than using the Windows Task Scheduler.Youshould
onlyuse at if your test system does not support the Task Scheduler or if you areintegrating a
newtest harness system into an existing system that uses the at command.
注解
对于大部分轻量级自动化场景,使用.BAT文件管理多个测试套件既简单又有效。编写一个C#主套件,在该套件中并列调用需要运行的测试套件同样可行。我们可以使用System.Diagnostics.Process命名空间下的Start()静态方法调用需要运行的测试套件:Console.WriteLine("Starting testautomation sequence\n");
Process.Start("C:\\TestHarness1\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness2\\bin\\Debug\\Run.exe");
Process.Start("C:\\TestHarness3\\bin\\Debug\\Run.exe");
Console.WriteLine("\n Test automationsequence complete\n");
然后使用windows的任务计划计划该主程序的运行。使用.BAT的优点是简单。使用C#编写主程序实现的优点是当在前面调用的测试套件出现一些状况的时候,它更有能力处理如捕获异常、增加新的执行套件的逻辑分支等事件。
除了使用windows的任务计划让测试套件自动运行,我们也可以使用at命令来让测试套件或主测试套件程序自动运行。使用at命令要不使用windows任务计划要复杂。我们仅仅在测试系统不支持任务计划或者将新的测试套件系统整合到使用at命令的系统中的时候才用at命令。
相关文章推荐
- net自动化测试之道API测试-确定测试套件运行的总时间
- net自动化测试之道API测试-自动发送Email报告测试失败
- net自动化测试之道API测试-用时间戳区别测试结果
- net自动化测试之道API测试-处理输入为null/期望结果为null的情况
- net自动化测试之道API测试-数据转换
- net自动化测试之道API测试-统计测试结果
- net自动化测试之道API测试-测试抛出异常的方法
- net自动化测试之道API测试-确定测试结果
- net自动化测试之道API测试-用空串测试
- Postman 、Newman运行自动API测试
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
- net自动化测试之道API测试-引言
- net自动化测试之道API测试-存储测试用例
- net自动化测试之道API测试-读取测试用例
- net自动化测试之道API测试-分解一个测试用例
- net自动化测试之道API测试-例子程序:ApiTest
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
- 自动化测试脚本的编写和执行——自动执行cts测试10遍
- .NET自动化测试---API轻量级测试
- 安装程序自动检测安装.Net Framework运行环境(使用InnoSetup)