Home All Groups Group Topic Archive Search About

PRoblem with System.Windows.Forms.Application.StartupPath when running test project

Author
17 Oct 2007 9:29 AM
Patrik
Hi,

I am not sure this is the right forum but I will give it a try. I am using
the built-in test project template that exists in Visual Studio Team
Edition. This project runs unit test on code that is using the property
System.Windows.Forms.Application.StartupPath. Normaly this gives me the
start location of my exe. The problem is that when running the test this
return the location of C:\Program Files\Microsoft Visual Studio
8\Common7\IDE which probably is the location of some unit tester.

I do not know how to solve this. The code is looking for a folder called
StandardIcons which do not ofcourse exist in the IDE folder. When I then try
to get files from that location I will get an DirectoryNotFound exception.

Any suggestions on how to handle this?

/Patrik

Author
18 Oct 2007 5:47 AM
Linda Liu[MSFT]
Hi Patrik,

This is a quick note to let you know that I'm performing research on this
issue and will get the result back to you ASAP.

I appreciate your patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
19 Oct 2007 6:44 AM
Linda Liu[MSFT]
Hi Patrik,

I performed a test based on your description and did reproduce the problem.

If I use the Application.ExecutablePath property in the tested method, the
returned result is 'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\VSTestHost.exe'. It is obvious that it's the VSTestHost.exe
that runs and hosts the resulted assemblies of the test project and WinForm
project when the test is run.

To solve this problem, I suggest that you pass the location of the folder
'StandardIcons' explicitly to the unit test method to get file from that
location.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
Author
22 Oct 2007 8:08 AM
Patrik
Hi,
thanks for the reply!

A solution would ofcourse be to copy the folder "Standard Icons" to the
directory where VSTestHost.exe is located. I though find it strange that
microsoft have not thought about this problem. It must be a common problem
for many developers out there. I had hoped that there would be a more
generic way of solving the problem then to copy files in an post build
script.

/Patrik

Show quote
"Linda Liu[MSFT]" <v-l***@online.microsoft.com> wrote in message
news:wrGt9thEIHA.1428@TK2MSFTNGHUB02.phx.gbl...
> Hi Patrik,
>
> I performed a test based on your description and did reproduce the
> problem.
>
> If I use the Application.ExecutablePath property in the tested method, the
> returned result is 'C:\Program Files\Microsoft Visual Studio
> 8\Common7\IDE\VSTestHost.exe'. It is obvious that it's the VSTestHost.exe
> that runs and hosts the resulted assemblies of the test project and
> WinForm
> project when the test is run.
>
> To solve this problem, I suggest that you pass the location of the folder
> 'StandardIcons' explicitly to the unit test method to get file from that
> location.
>
> Hope this helps.
> If you have any question, please feel free to let me know.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
Author
25 Oct 2007 10:13 AM
Linda Liu[MSFT]
Hi Patrik,

Thank you for your feedback!

I understand your concern. I am performing more research on this issue and
will get the result abck to you ASAP.

I appreciate your patience!

Sincerely,
Linda Liu
Microsoft Online Community Support
Author
26 Oct 2007 8:14 AM
Linda Liu[MSFT]
Hi Patrik,

After doing some more research, I found the solution.

The test engine runs tests not in the folder in which you have created or
generated them, but in a separate deployment folder. The deployment folder
can be local or remote. Remote test deployment occurs when you work with
controllers and agents.

For local test deployment, test engine copies deployment items, both files
and folders, to a folder on your computer before it runs tests.

There're several ways to deploy files or folders to the deployment folder.
You may refer to the following MSDN document on how to configure Test
Deployment:

'How to: Configure Test Deployment'
http://msdn2.microsoft.com/en-us/library/ms182475(vs.80).aspx

In your scenario, you can deploy the folder 'StandardIcons' to the
subdirectory named 'StandardIcons' of the deployment root directory. To do
this, you have two options.

Option 1: through run configuration
1. Follow the steps in the section 'To select files or folders to deploy,
in run configuration' in the above MSDN document to deploy the folder
'StandardIcons' to the  deployment root directory.

2. Right-click the <run config file name>.testrunconfig in the Solution
Explorer and choose Open With. In the Open With dialog, choose 'XML Editor'
and click OK button.

3. In the <run config file name>.testrunconfig file, navigate to the tag
'<deploymentItems>' and add the 'StandardIcons' in the tag
'<outputDirectory>'. For example:

<deploymentItems
type="Microsoft.VisualStudio.TestTools.Common.DeploymentItemCollection">
      <m_container type="System.Collections.Hashtable">
        <key type="Microsoft.VisualStudio.TestTools.Common.DeploymentItem">
          <path type="System.String">TestProject1\StandardIcons\</path>
          <outputDirectory
type="System.String">StandardIcons</outputDirectory>
        </key>
        <value />
      </m_container>
</deploymentItems>

Option 2: through the DeploymentItemAttribute
1. Copy the folder 'StandardIcons' under the test project folder.

2. Follow the steps in section 'To deploy items for a single test using the
DeploymentItem attribute' in the above MSDN document.

3. You need specify the second parameter for the DeploymentItemAttribute
constructor, for example:

[TestMethod()]
[DeploymentItem("TestProject1\\StandardIcons","StandardIcons")]
public void MyTestMethod()
{....}

After you deploy the entire directory of 'StandardIcons' to the deployment
root folder, you  you can access the directory 'StandardIcons' directly in
the test method. For example:
[TestMethod()]
[DeploymentItem("TestProject1\\StandardIcons","StandardIcons")]
public void MyTestMethod()
{
            Form1 target = new Form1();
           // pass the file path to the method to test
            actual = target.ReadFile("StandardIcons\\MyText.txt");         

}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

AddThis Social Bookmark Button