views:

452

answers:

1

I'm using Visuial Studio's Coded UI Tests to run Automated UI tests on a WPF Application everytime a build runs on my TFS server. The problem I am running into is dynamically launching the executable based on the path where it was just built to, including the configuration(x86, x64).

Is there any way to get the path to an executable in a referenced project so that I can launch the application dynamically from my test project?

+3  A: 

MSTest:

  1. Open your .testsettings file and check the "Enable Deployment" under the deployment section.
  2. In your test project right-click and select Add Existing Item.
  3. Browse to the build location of your application to test.
  4. Find your executable and select "Add as link" (make sure you either include all of your apps dependent DLL's if they are not already referenced by your test project.)
  5. Right click the link to the executable and select "Copy Always" (this will copy a new version of the .exe to your tests bin directory when it is built)
  6. In your [TestInitialize] add the following to launch your app:

    _yourApp = ApplicationUnderTest.Launch(Path.Combine(Directory.GetCurrentDirectory(), "yourexecutablename.exe"));
  7. In your [TestCleanup] you add the following:

    _yourApp.Close();

NUnit: (you will need to reference and use Microsoft.VisualStudio.TestTools.UITesting)

  1. In your test project right-click and select Add Existing Item.
  2. Browse to the build location of your application to test.
  3. Find your executable and select "Add as link" (make sure you either include all of your apps dependent DLL's if they are not already referenced by your test project.)
  4. Right click the link to the executable and select "Copy Always" (this will copy a new version of the .exe to your tests bin directory when it is built)
  5. In your [Setup] add the following to launch your app:

    _yourApp = ApplicationUnderTest.Launch("yourexecutablename.exe"));
  6. In your [Teardown] you add the following:

    _yourApp.Close();

note: I have not verified the NUnit implementation

Adam
+1 Awesome step by step explanation.
Lernkurve