|
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="SoapUIHome" value="C:\Program Files\SmartBear\SoapUI-5.3.0\bin"/> </appSettings> </configuration> |
using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoapUI { public class SoapUIRunner { public void RunSoapUItest(string soapProject,string testSuiteName,string testName,string report,string set) { const string fileName = "cmd.exe"; var soapProjectFileName = Path.GetFullPath(soapProject); var
arguments = string.Format("/C testrunner.bat -s\"{0}\" -c\"{1}\"
\"{2}\" -r -a -f\"{3}\" -t\"{4}\" ", testSuiteName, testName,
soapProjectFileName, report, set); var soapHome = System.Configuration.ConfigurationManager.AppSettings["SoapUIHome"]; //start a process and hook up the in/output var process = new Process { StartInfo = new ProcessStartInfo { FileName = fileName, Arguments = arguments, WorkingDirectory = soapHome, Verb = "runas", CreateNoWindow = true, ErrorDialog = false, RedirectStandardError= true, RedirectStandardOutput = true, UseShellExecute = false }, EnableRaisingEvents = true }; //pipe the output to console.writeline process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data); var errorBuilder = new StringBuilder(); //store the errors in a stringbuilder process.ErrorDataReceived += (sender, args) => { if (args != null && args.Data != null) { errorBuilder.AppendLine(args.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); //wait for soapUI to finish process.WaitForExit(); //fail the test if anything fails var errorMessage = errorBuilder.ToString(); if(!string.IsNullOrEmpty(errorMessage)) { Assert.Fail("Test with name '{0}' failed. {1} {2}", testName, Environment.NewLine, errorMessage); } } } } |
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SoapUI { [TestClass] [DeploymentItem(@"soapUIFiles\DeviceReportService-soapui-project.xml", "TestData\\soapUIFiles")] public class DeviceReport:SoapUIRunner { private string testCaseSuiteName = "BasicHttpBinding_DeviceReport TestSuite"; private string soapProjectFile= @"TestData\\soapUIFiles\\DeviceReportService-soapui-project.xml"; private string reportFile = @"C:\Users\" + Environment.UserName + "\\Desktop\\TestReport"; private String SoapUISettingsFile = @"TestData\\soapUIFiles\\soapui-settings.xml"; private TestContext testContext; public TestContext TestContext { get { return this.testContext; } set { this.testContext = value; } } [TestMethod] [TestCategory("DeviceReport")] public void Device_Report() { RunSoapUItest(soapProjectFile, testCaseSuiteName, "DeviceReport TestCase", reportFile, SoapUISettingsFile); } } } |