Reputation: 11717
My scenario is as follows: I'm working on a cross-platform mobile app with Xamarin.Forms. Part of this solution are unit test projects that target iOS/Android/WP8, and the tests that are executed on each platform are in a shared library.
The tests are written with the xUnit.Net framework.
Now I have some tests that succeed on all mobile platforms, but not on Windows (i.e. when I run them from within VS during development):
// in a PCL (which is referenced by platform-specific unit test projects)
[Fact]
public void SomeTest()
{
// succeeds on iOS, Android, and WinPhone
// fails on Windows (when executed from within Visual Studio)
}
I don't want to run each single test from each mobile platform during development each and every time - that would be very time-consuming. Of course, I only do that in bigger chunks.
The consequence is that I have a bunch of unit tests which fail in VS, and I cannot see if it's a 'real' error or 'only' a platform-specific problem. Rather, I'd like to see immediately what the problem is and not have dozens of red tests which I have to inspect individually.
Does anyone know how to do that?
Upvotes: 2
Views: 1196
Reputation: 98
You can just add some check in front of a test:
[TestMethod]
public void Some_Test()
{
if (!OperatingSystem.IsWindows())
{
return;
}
var testCount = 3;
Assert.IsTrue(testCount > 0);
}
Upvotes: 0
Reputation: 32936
Can you not use traits to achieve this?
ie add a trait which specifies that the tests shouldn't be run on windows then you can execute only tests which don't have this trait in visual studio using whatever test runner you are using.
Upvotes: 2
Reputation: 7934
If you are creating different builds for each platform (as I'm sure you must be) why not exclude the tests you don't want to run using a compilation preprocessor directive?
You could then pass in the value WINDOWS
during compilation in VS and exclude the test using:
#if !WINDOWS
[Fact]
public void SomeTest()
{
// succeeds on iOS, Android, and WinPhone
// fails on Windows (when executed from within Visual Studio)
}
#endif
More information of how Preprocessor directives are used available here: MSDN: C# Preprocessor Directives
Upvotes: 0