Zoeken…


Invoering

Het automatiseren van Infrastructure Management Services resulteert in het verminderen van de VTE en cumulatief betere ROI met behulp van meerdere tools, orchestrators, orchestration Engine, scripts en eenvoudige UI

Eenvoudig script voor black-box integratietest van console-applicaties

Dit is een eenvoudig voorbeeld van hoe u tests kunt automatiseren voor een consoletoepassing die interageert met standaardinvoer en standaarduitvoer.

De geteste applicatie leest en somt elke nieuwe regel op en geeft het resultaat nadat een enkele witte lijn is opgegeven. Het power shell-script schrijft "pass" wanneer de uitvoer overeenkomt.

$process = New-Object System.Diagnostics.Process
$process.StartInfo.FileName = ".\ConsoleApp1.exe"
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.RedirectStandardInput = $true
if ( $process.Start() ) {
    # input
    $process.StandardInput.WriteLine("1");
    $process.StandardInput.WriteLine("2");
    $process.StandardInput.WriteLine("3");
    $process.StandardInput.WriteLine();
    $process.StandardInput.WriteLine();
    # output check
    $output = $process.StandardOutput.ReadToEnd()
    if ( $output ) {
        if ( $output.Contains("sum 6") ) {
            Write "pass"
        }
        else {
            Write-Error $output
        }
    }
    $process.WaitForExit()
}


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow