End2End Automated Testing: Calling Applications Remotely

Calling a remote application, you want it to run almost always in its native directory and not against your calling End2End code's directory. Why? You don't want to have to verify whether the application uses or will use any kind of relative paths.  You want your End2End Tests to work in any respect.  So you can implement the basic code for starting a process using the System.IO and System.Diagnostics .Net libraries.

 

Public Sub RunApplication(ByVal filePath As String, ByVal args As String, ByVal waitForExit As Boolean, ByVal setWorkingDirectoryToPath As Boolean)
     Dim processStartInfo As New ProcessStartInfo(filePath, String.Format(" {0}", args))
     processStartInfo.UseShellExecute = False
     processStartInfo.RedirectStandardOutput = False
     processStartInfo.CreateNoWindow = False
     If (setWorkingDirectoryToPath) Then
         processStartInfo.WorkingDirectory = Path.GetDirectoryName(filePath)
     End If
 
     RunProcess(processStartInfo, waitForExit)
 End Sub
 
 Private Sub RunProcess(ByVal processInfo As ProcessStartInfo, ByVal waitForExit As Boolean)
     Using process As New Process()
         process.StartInfo = processInfo
         process.Start()
 
         If (waitForExit) Then
             process.WaitForExit()
         End If
     End Using
 End Sub

posted @ Monday, June 23, 2008 8:44 AM

Print

Comments on this entry:

# re: End2End Automated Testing: Calling Applications Remotely

Left by Dewayne Christensen at 6/23/2008 10:26 AM
Gravatar
And since you want to write robust code, you add an exception handler to make sure Dispose always gets called:


Dim process As New Process()
Try
...
Finally
process.Dispose()
End Try


Or in VB.NET 2:


Using process As New Process()
...
End Using


Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 3 and type the answer here:
 

Live Comment Preview:

 
«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456