Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrik - 17 Oct 2007 10:29 GMT
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
Linda Liu[MSFT] - 18 Oct 2007 06:47 GMT
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.
Linda Liu[MSFT] - 19 Oct 2007 07:44 GMT
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
Patrik - 22 Oct 2007 09:08 GMT
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

> Hi Patrik,
>
[quoted text clipped - 18 lines]
> Linda Liu
> Microsoft Online Community Support
Linda Liu[MSFT] - 25 Oct 2007 11:13 GMT
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
Linda Liu[MSFT] - 26 Oct 2007 09:14 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.