zoukankan      html  css  js  c++  java
  • 自动化生成 日志

    脚本的执行步骤必须明确、并且可控、而且还要有详细的日志、结果输出,以便出现问题进行定位。

    自动化脚本不应该只停留在执行上,还必须有对结果进行判断的能力,碰到异常能够做相应的处理。所以日志输出结果很重要。

    http://stackoverflow.com/questions/19966054/execute-command-line-statements-from-within-nunit

    一.可以使用nunit 自动执行日志代码

    
    

    1.cmd进入到nunit-console.exe路径(或者配置环境变量)

    2.输入nunit-console.exe -h(-h为help),可以得出以下信息:

    Options:
    /fixture=STR Test fixture or namespace to be loaded (Deprecated) (Sho
    rt format: /load=STR)
    /run=STR Name of the test case(s), fixture(s) or namespace(s) to
    run
    /runlist=STR Name of a file containing a list of the tests to run, on
    e per line
    /config=STR Project configuration (e.g.: Debug) to load
    /result=STR Name of XML result file (Default: TestResult.xml) (Short
    format: /xml=STR)
    /xmlConsole Display XML to the console (Deprecated)
    /noresult Suppress XML result output (Short format: /noxml)
    /output=STR File to receive test output (Short format: /out=STR)
    /err=STR File to receive test error output
    /work=STR Work directory for output files
    /labels Label each test in stdOut
    /trace=X Set internal trace level: Off, Error, Warning, Info, Ver
    bose
    /include=STR List of categories to include
    /exclude=STR List of categories to exclude
    /framework=STR Framework version to be used for tests
    /process=X Process model for tests: Single, Separate, Multiple
    /domain=X AppDomain Usage for tests: None, Single, Multiple
    /apartment=X Apartment for running tests: MTA (Default), STA
    /noshadow Disable shadow copy when running in separate domain
    /nothread Disable use of a separate thread for tests
    /basepath=STR Base path to be used when loading the assemblies
    /privatebinpath=STR Additional directories to be probed when loading assembl
    ies, separated by semicolons
    /timeout=X Set timeout for each test case in milliseconds
    /wait Wait for input before closing console window
    /nologo Do not display the logo
    /nodots Do not display progress
    /stoponerror Stop after the first test failure or error
    /cleanup Erase any leftover cache files and exit
    /help Display help (Short format: /?)

    输入:nunit-console.exe dll路径 /output d:	emplog.txt(内容包含console信息)(如图1)
    nunit-console.exe dll路径 /result d:	emp
    esult.xml(如图2)

    图1
     

    图2

     

    二.可以直接在测试中加入代码

                string stamp = DateTime.Now.ToString("s");
                stamp = stamp.Replace(":", "-");
                string path1 = "d:\temp\TestResluts-" + stamp + ".txt";
              
                FileStream fsStream = new FileStream(path1, FileMode.Create);
                StreamWriter swWriter = new StreamWriter(fsStream);
                swWriter.WriteLine("测试结果为:" + caseID +"Pass");
    
    
    
     
  • 相关阅读:
    20172313 2018-2019-1 《程序设计与数据结构》第七周学习总结
    20172313 2018-2019-1 《程序设计与数据结构》第六周学习总结
    20172313 2018-2019-1 《程序设计与数据结构》课堂测试修改报告
    20172313 2018-2019-1 《程序设计与数据结构》第五周学习总结
    2019_软工实践_个人总结
    2019_软工实践_Beta收官
    2019_软工实践_Beta(5/5)
    2019_软工实践_Beta(4/5)
    2019_软工实践_Beta(3/5)
    2019_软工实践_Beta(2/5)
  • 原文地址:https://www.cnblogs.com/cloud-test/p/3480562.html
Copyright © 2011-2022 走看看