Skip to content

Enable custom unit test location with standard location fallback #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;

namespace LibGit2Sharp.Tests.TestHelpers
Expand Down Expand Up @@ -34,7 +35,7 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom

public static string BuildPath()
{
string tempPath;
string tempPath = null;

var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");

Expand All @@ -48,11 +49,24 @@ public static string BuildPath()
}
else
{
const string LibGit2TestPath = "LibGit2TestPath";
// We're running on .Net/Windows
tempPath = Path.GetTempPath();
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For troubleshooting purpose, it may be worth adding a Trace.WriteLine call with something along LibGit2TestPath environment variable has been detected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - is this output expected to be displayed when run from the console (or from the xunit runner in Visual Studio)? Did we confirm that it is actually displayed? I am not sure where the Trace output actually goes if one didn't hook up a trace listener.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamill There are similar calls in DirectoryHelper. They're being displayed in Visual Studio output window when ran through TestDriven.Net runner

------ Test started: Assembly: LibGit2Sharp.Tests.dll ------

Output from LibGit2Sharp.Tests.ArchiveFixture.ArchivingANullTreeOrCommitThrows:
  ProcessInvocation86.exe Information: 0 : Using default test path value
  ProcessInvocation86.exe Information: 0 : Test working directory set to 'C:\Users\Em\AppData\Local\Temp\LibGit2Sharp-TestRepos'

3 passed, 0 failed, 0 skipped, took 5,92 seconds (xUnit.net 1.9.2 build 1705).

They're also intercepted by the Resharper test runners

JetBrains.ReSharper.TaskRunner.CLR4.x64.exe Information: 0 : Using default test path value
JetBrains.ReSharper.TaskRunner.CLR4.x64.exe Information: 0 : Test working directory set to 'C:\Users\Em\AppData\Local\Temp\LibGit2Sharp-TestRepos'

and the VisualStudio test runner

Test Name:  LibGit2Sharp.Tests.ArchiveFixture.CanArchiveATree
Test Outcome:   Passed
Result StandardOutput:  
vstest.executionengine.x86.exe Information: 0 : Using default test path value
vstest.executionengine.x86.exe Information: 0 : Test working directory set to 'C:\Users\Em\AppData\Local\Temp\LibGit2Sharp-TestRepos'

Although in those last two cases, they're associated with the output of the first test that is ran.

{
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a new line after this brace?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea very much! And the speed bump may be very neat for contributors.

How would you feel about a brief note in the README (not in the wiki) quickly explaining how to run the tests and how to leverage this neat addition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, though is it kosher to directly mention a third-party app?

{
Trace.TraceInformation("Using default test path value");
tempPath = Path.GetTempPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a Trace.WriteLine stating LibGit2TestPath content ('{0}') doesn't lead to an existing path. Falling back to default location.

}
}

return Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
string testWorkingDirectory = Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
Trace.TraceInformation("Test working directory set to '{0}'", testWorkingDirectory);
return testWorkingDirectory;
}
}
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ More thorough information available in the [wiki][wiki].

[wiki]: https://github.com/libgit2/libgit2sharp/wiki

## Optimizing unit testing
LibGit2Sharp strives to have comprehensive and robust unit test suite to insure the quality of the software and to assist new contributors and users who can use the tests as sample to jump start development. There are over one-thousand unit-tests for LibGit2Sharp, this number will only grow as functionality is added.

You can do a few things to optimize running unit-tests on Windows:

1. Set the `LibGit2TestPath` environment variable to a path in your development environment.
* If the unit-test framework cannot find the specified folder at runtime, it will fall back to the default location.
2. Configure your anti-virus software to ignore the `LibGit2TestPath` path.
3. Install a RAM disk like [IMDisk](http://www.ltr-data.se/opencode.html/#ImDisk) and set `LibGit2TestPath` to use it.
* Use `imdisk.exe -a -s 256M -m X: -p "/fs:fat /q /v:ramdisk /y"` to create a RAM disk. This command requires elevated privileges and can be placed into a scheduled task or run manually before you begin unit-testing.

## Authors

- **Code:** The LibGit2Sharp [contributors][committers]
Expand Down