Bob
Bob

Reputation: 4386

TFS: how to reference the output directory in C#

Using VS2010 i have a test that calls a method which runs a command line command that outputs a file.

The file is outputted to: ...\TestResults\xxxxxx 2011-02-04 09_45_46\Out

I want to test that the file got successfully written

Is there some way of referencing this path without hard coding it?

Upvotes: 1

Views: 1915

Answers (5)

Yam Marcovic
Yam Marcovic

Reputation: 8141

Sorry, I get you now.

You can just use the TestContext property that comes with Unit Test classes. You have properties like ResultDirectory, TestDir, TestDeploymentDir, etc...

If you don't have it in your TestClass, just add a public TestContext property called TestContext.

It's best to just create a new Unit Test class and see how it's used.

Upvotes: 1

Ryan Cromwell
Ryan Cromwell

Reputation: 2613

The other, more robust IMHO, option is to provide an output path to the command line utility which you can specify as a known location (ie Path.GetTempPath or Path.GetRandomFileName). That way you aren't embedding test runner dependencies that are fragile.

Upvotes: 0

Dave
Dave

Reputation: 3621

I had to do this yesterday:

string outputDir = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName

Upvotes: 2

Yam Marcovic
Yam Marcovic

Reputation: 8141

You can specify special variables in the build events of the project.

Here's a reference: Macros for Build Commands and Properties

I reckon OutDir or TargetDir is what you might be looking for.

Upvotes: 0

alex
alex

Reputation: 3720

Are you referring to the xxxxxx 2011-02-04 09_45_46 part in your path? You could just go through the folders in the ...\TestResults\ path, get the last folder (which is hopefully the one you want) and just use Path.Combine to create your complete path. Then, all you need to do is check and see if the file is there.

Upvotes: 0

Related Questions