Browse Source

ImageSharp.Tests (.NET Core!) test profiling is now possible from R# context menu

af/merge-core
Anton Firszov 9 years ago
parent
commit
f949f464ea
  1. 11
      tests/ImageSharp.Sandbox46/README.md
  2. 30
      tests/ImageSharp.Tests/TestFile.cs

11
tests/ImageSharp.Sandbox46/README.md

@ -1,7 +1,7 @@
## Purpose
This project aims to workaround certain .NET Core tooling issues in Visual Studio based developer workflow at the time of it's creation (January 2017):
- .NET Core Performance profiling is not possible neither with Visual Studio nor with JetBrains profilers
- JetBrains Unit Test explorer does not work with .NET Core projects
- ~~JetBrains Unit Test explorer does not work with .NET Core projects~~
## How does it work?
- By referencing .NET 4.5 dll-s created by net45 target's of ImageSharp projects. NOTE: These are not project references!
@ -16,10 +16,9 @@ This project aims to workaround certain .NET Core tooling issues in Visual Studi
- Use the [context menu in Test Explorer](https://adamprescott.net/2012/12/12/performance-profiling-for-unit-tests/)
NOTE:
There was no *Profile test* option in my VS Professional. Maybe things were messed by VS2017 RC installation. [This post suggests](http://stackoverflow.com/questions/32034375/profiling-tests-in-visual-studio-community-2015) it's necessary to won Premium or Ultimate edition of Visual Studio to profile tests.
There was no *Profile test* option in my VS Professional. Maybe things were messed by VS2017 RC installation. [This post suggests](http://stackoverflow.com/questions/32034375/profiling-tests-in-visual-studio-community-2015) it's necessary to own Premium or Ultimate edition of Visual Studio to profile tests.
#### 2. With JetBrains ReSharper Ultimate
- Use the [context menu](https://www.jetbrains.com/resharper/features/unit_testing.html) from your test class
![Context Menu](https://www.jetbrains.com/resharper/features/screenshots/100/unit_testing_profiling.png)
- Or Unit Test Exporer or Unit Test Sessions
- When working with test classes, make sure you open them from the `ImageSharp.Sandbox46` project!
- The `Sandbox46` project is no longer needed here. The classic `ImageSharp.Tests` project can be discovered by Unit Test Explorer.
- You can use [context menus](https://www.jetbrains.com/resharper/features/unit_testing.html) from your test class, or from unit Test Exporer/Unit Test Sessions windows.
![Context Menu](https://www.jetbrains.com/resharper/features/screenshots/100/unit_testing_profiling.png)

30
tests/ImageSharp.Tests/TestFile.cs

@ -5,9 +5,12 @@
namespace ImageSharp.Tests
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
/// <summary>
/// A test image file.
@ -130,14 +133,19 @@ namespace ImageSharp.Tests
/// </returns>
private static string GetFormatsDirectory()
{
var directories = new[] {
List<string> directories = new List< string > {
"TestImages/Formats/", // Here for code coverage tests.
"tests/ImageSharp.Tests/TestImages/Formats/", // from travis/build script
"../../../ImageSharp.Tests/TestImages/Formats/", // from Sandbox46
"../../../../TestImages/Formats/"
};
directories= directories.Select(x => Path.GetFullPath(x)).ToArray();
directories = directories.SelectMany(x => new[]
{
Path.GetFullPath(x)
}).ToList();
AddFormatsDirectoryFromTestAssebmlyPath(directories);
var directory = directories.FirstOrDefault(x => Directory.Exists(x));
@ -148,5 +156,23 @@ namespace ImageSharp.Tests
throw new System.Exception($"Unable to find Formats directory at any of these locations [{string.Join(", ", directories)}]");
}
/// <summary>
/// The path returned by Path.GetFullPath(x) can be relative to dotnet framework directory
/// in certain scenarios like dotTrace test profiling.
/// </summary>
/// <param name="directories">The directories list</param>
private static void AddFormatsDirectoryFromTestAssebmlyPath(List<string> directories)
{
string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location;
assemblyLocation = Path.GetDirectoryName(assemblyLocation);
if (assemblyLocation != null)
{
string dirFromAssemblyLocation = Path.Combine(assemblyLocation, "../../../TestImages/Formats/");
dirFromAssemblyLocation = Path.GetFullPath(dirFromAssemblyLocation);
directories.Add(dirFromAssemblyLocation);
}
}
}
}

Loading…
Cancel
Save