Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links

News


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for



Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!

Archives

Post Categories

Sites

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

Print | posted on Monday, June 23, 2008 8:44 AM | Filed Under [ Code ]

Feedback

Gravatar

# re: End2End Automated Testing: Calling Applications Remotely

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


6/23/2008 10:26 AM | Dewayne Christensen
Comments have been closed on this topic.

Powered by: