代码之家  ›  专栏  ›  技术社区  ›  Brian R. Bondy

使用批处理文件的测试自动化:

  •  2
  • Brian R. Bondy  · 技术社区  · 16 年前

    我的测试套件有以下布局:

    TestSuthe1.CMD:

    1. 运行我的程序
    2. 检查其返回结果
    3. 如果返回结果不是0,请将错误转换为文本输出并中止脚本。如果成功,写下成功。

    在我的single.cmd文件中,我用不同的输入调用程序大约10次。

    问题是我运行10次的程序每次运行需要几个小时。

    有没有一种方法可以让我在检查返回结果并提供适当的输出文件的同时,同时仍然使用 单一的 .cmd文件和单个输出文件?

    5 回复  |  直到 16 年前
        1
  •  4
  •   paxdiablo    16 年前

    假设它们不会通过写入相同的文件等相互干扰:

    Test1.CMD

    :: intercept sub-calls.
      if "%1"=="test2" then goto :test2
    
    :: start sub-calls.
      start test1.cmd test2 1
      start test1.cmd test2 2
      start test1.cmd test2 3
    
    :: wait for sub-calls to complete.
    :loop1
      if not exist test2_1.flg goto :loop1
    :loop2
      if not exist test2_2.flg goto :loop2
    :loop3
      if not exist test2_3.flg goto :loop3
    
    :: output results sequentially
      type test2_1.out >test1.out
        del /s test2_1.out
        del /s test2_1.flg
      type test2_2.out >test1.out
        del /s test2_2.out
        del /s test2_2.flg
      type test2_3.out >test1.out
        del /s test2_3.out
        del /s test2_3.flg
    
      goto :eof
    :test2
    
    :: Generate one output file
      echo %1 >test2_%1.out
      ping -n 31 127.0.0.1 >nul: 2>nul:
    
    :: generate flag file to indicate finished
      echo x >test2_%1.flg
    

    这将启动三个并发进程,每个进程都会回显其序列号,然后等待30秒。

    都有一个命令文件和(最终)一个输出文件。

        2
  •  1
  •   INS    16 年前

    可以通过“start”可执行文件/命令并行运行批处理文件。

        3
  •  1
  •   KARASZI István    16 年前

    窗户:

    创建一个批处理文件,它基本上调用:

    start TestSuite1.cmd [TestParams1]
    start TestSuite1.cmd [TestParams2]
    

    等等,基本上是分叉新的命令行,

    如果应用程序能够处理并发用户(即使它是同一个用户),并且testsuite1.cmd能够处理参数,那么这将起作用。

        4
  •  0
  •   xmjx    16 年前

    您将需要使用不同的参数启动脚本 在不同的机器上 因为无论是什么让程序花费这么长的时间来完成一项任务(IO、CPU时间),当您的程序同时运行多个实例时,它的供应量会更短。

    唯一的例外是:运行时间是由程序自己进入睡眠状态引起的。

        5
  •  0
  •   grapefrukt    16 年前

    尝试命令 开始 它会产生一个新的命令提示,您可以发送希望它运行的任何命令。

    我将使用它生成运行测试的批处理文件,然后使用>>将其附加到output.txt,例如:

    testthingie.cmd >> output.txt