Skip to content
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

Added tests for netcoreapp1.1 #270

Merged
merged 6 commits into from
Dec 13, 2016
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
6 changes: 3 additions & 3 deletions TestPlatform.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26008.9
VisualStudioVersion = 15.0.26009.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}"
EndProject
Expand Down Expand Up @@ -632,8 +632,8 @@ Global
{57B182B8-9014-4C6D-B966-B464DE3127D5}.Release|x64.Build.0 = Release|x64
{57B182B8-9014-4C6D-B966-B464DE3127D5}.Release|x86.ActiveCfg = Release|x86
{57B182B8-9014-4C6D-B966-B464DE3127D5}.Release|x86.Build.0 = Release|x86
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|Any CPU.Build.0 = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|x64.ActiveCfg = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|x64.Build.0 = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Debug|x86.ActiveCfg = Release|Any CPU
Expand Down
58 changes: 20 additions & 38 deletions test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,26 @@ namespace Microsoft.TestPlatform.AcceptanceTests

public class AcceptanceTestBase : IntegrationTestBase
{
private const string DesktopRunnerFramework = "net46";
private const string CoreRunnerFramework = "netcoreapp1.0";
private const string DesktopTargetFramework = "net46";
private const string CoreTargetFramework = "netcoreapp1.0";
public const string DesktopRunnerFramework = "net46";
public const string CoreRunnerFramework = "netcoreapp1.0";
public const string DesktopTargetFramework = "net46";
public const string CoreTargetFramework = "netcoreapp1.0";
public const string Core11TargetFramework = "netcoreapp1.1";

private const string CoreFrameworkArgValue = ".NETCoreApp,Version=v1.0";
private const string DesktopFrameworkArgValue = ".NETFramework,Version=v4.6";
private const string DesktopRunnerTargetRuntime = "win7-x64";
private const string CoreRunnerTargetRuntime = "";
public const string CoreFrameworkArgValue = ".NETCoreApp,Version=v1.0";
public const string Core11FrameworkArgValue = ".NETCoreApp,Version=v1.1";
public const string DesktopFrameworkArgValue = ".NETFramework,Version=v4.6";
public const string DesktopRunnerTargetRuntime = "win7-x64";
public const string CoreRunnerTargetRuntime = "";

protected string FrameworkArgValue => DeriveFrameworkArgValue(this.testEnvironment);

protected static void SetupRunnerCoreTargetDesktopEnvironment(
IntegrationTestEnvironment testEnvironment)
protected static void SetTestEnvironment(IntegrationTestEnvironment testEnvironment,
string runnerFramework, string targetFramework, string targetRuntime)
{
testEnvironment.RunnerFramework = CoreRunnerFramework;
testEnvironment.TargetFramework = DesktopTargetFramework;
testEnvironment.TargetRuntime = CoreRunnerTargetRuntime;
}

protected static void SetupRunnerDesktopTargetDesktopEnvironment(
IntegrationTestEnvironment testEnvironment)
{
testEnvironment.RunnerFramework = DesktopRunnerFramework;
testEnvironment.TargetFramework = DesktopTargetFramework;
testEnvironment.TargetRuntime = DesktopRunnerTargetRuntime;
}

protected static void SetupRunnerCoreTargetCoreEnvironment(
IntegrationTestEnvironment testEnvironment)
{
testEnvironment.RunnerFramework = CoreRunnerFramework;
testEnvironment.TargetFramework = CoreTargetFramework;
testEnvironment.TargetRuntime = CoreRunnerTargetRuntime;
}

protected static void SetupRunnerDesktopTargetCoreEnvironment(
IntegrationTestEnvironment testEnvironment)
{
testEnvironment.RunnerFramework = DesktopRunnerFramework;
testEnvironment.TargetFramework = CoreTargetFramework;
testEnvironment.TargetRuntime = DesktopRunnerTargetRuntime;
testEnvironment.RunnerFramework = runnerFramework;
testEnvironment.TargetFramework = targetFramework;
testEnvironment.TargetRuntime = targetRuntime;
}

protected static string DeriveFrameworkArgValue(IntegrationTestEnvironment testEnvironment)
Expand All @@ -60,6 +38,10 @@ protected static string DeriveFrameworkArgValue(IntegrationTestEnvironment testE
{
framworkArgValue = CoreFrameworkArgValue;
}
else if (string.Equals(testEnvironment.TargetFramework, Core11TargetFramework, StringComparison.Ordinal))
{
framworkArgValue = Core11FrameworkArgValue;
}
else if (string.Equals(testEnvironment.TargetFramework, DesktopTargetFramework, StringComparison.Ordinal))
{
framworkArgValue = DesktopFrameworkArgValue;
Expand All @@ -80,7 +62,7 @@ protected bool IsDesktopRunner()

protected string GetTargetFramworkForRunsettings()
{
string targetFramework = string.Empty;
var targetFramework = string.Empty;
if(this.testEnvironment.TargetFramework == DesktopTargetFramework)
{
targetFramework = "Framework45";
Expand Down
10 changes: 7 additions & 3 deletions test/Microsoft.TestPlatform.AcceptanceTests/AppDomainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ namespace Microsoft.TestPlatform.AcceptanceTests

using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class AppDomainTests : AcceptanceTestBase
[TestClass]
public class AppDomainTests : AcceptanceTestBase
{
[TestMethod]
public virtual void RunTestExecutionWithDisableAppDomain()
[CustomDataTestMethod]
[NET46TargetFramework]
public void RunTestExecutionWithDisableAppDomain(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var testAppDomainDetailFileName = Path.Combine(Path.GetTempPath(), "appdomain_test.txt");
var dataCollectorAppDomainDetailFileName = Path.Combine(Path.GetTempPath(), "appdomain_datacollector.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ namespace Microsoft.TestPlatform.AcceptanceTests

using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class DifferentTestFrameworkSimpleTests : AcceptanceTestBase
[TestClass]
public class DifferentTestFrameworkSimpleTests : AcceptanceTestBase
{
[TestMethod]
public virtual void ChutzpahRunAllTestExecution()
[CustomDataTestMethod]
[NET46TargetFramework]
public void ChutzpahRunAllTestExecution(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var testJSFileAbsolutePath = Path.Combine(this.testEnvironment.TestAssetsPath, "test.js");
var arguments = PrepareArguments(
testJSFileAbsolutePath,
Expand All @@ -23,9 +27,12 @@ public virtual void ChutzpahRunAllTestExecution()
}

[Ignore]
[TestMethod]
public virtual void CPPRunAllTestExecution()
[CustomDataTestMethod]
[NET46TargetFramework]
public void CPPRunAllTestExecution(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var assemblyRelativePath =
@"microsoft.testplatform.testasset.nativecpp\1.0.0\contentFiles\any\any\Microsoft.TestPlatform.TestAsset.NativeCPP.dll";
var assemblyAbsolutePath = Path.Combine(this.testEnvironment.PackageDirectory, assemblyRelativePath);
Expand All @@ -38,9 +45,12 @@ public virtual void CPPRunAllTestExecution()
this.ValidateSummaryStatus(1, 0, 0);
}

[TestMethod]
public virtual void NUnitRunAllTestExecution()
[CustomDataTestMethod]
[NET46TargetFramework]
public void NUnitRunAllTestExecution(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var arguments = PrepareArguments(
this.GetAssetFullPath("NUTestProject.dll"),
this.GetTestAdapterPath(UnitTestFramework.NUnit),
Expand All @@ -50,9 +60,12 @@ public virtual void NUnitRunAllTestExecution()
this.ValidateSummaryStatus(1, 1, 0);
}

[TestMethod]
public void XUnitRunAllTestExecution()
[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void XUnitRunAllTestExecution(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);
var arguments = PrepareArguments(
this.GetAssetFullPath("XUTestProject.dll"),
this.GetTestAdapterPath(UnitTestFramework.XUnit),
Expand Down
11 changes: 8 additions & 3 deletions test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ namespace Microsoft.TestPlatform.AcceptanceTests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class DiscoveryTests : AcceptanceTestBase
[TestClass]
public class DiscoveryTests : AcceptanceTestBase
{
[TestMethod]
public void DiscoverAllTests()
[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void DiscoverAllTests(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

this.InvokeVsTestForDiscovery(this.GetSampleTestAssembly(), this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue);
var listOfTests = new string[] { "SampleUnitTestProject.UnitTest1.PassingTest", "SampleUnitTestProject.UnitTest1.FailingTest", "SampleUnitTestProject.UnitTest1.SkippingTest" };
this.ValidateDiscoveredTests(listOfTests);
Expand Down
19 changes: 14 additions & 5 deletions test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ namespace Microsoft.TestPlatform.AcceptanceTests

using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class ExecutionTests : AcceptanceTestBase
[TestClass]
public class ExecutionTests : AcceptanceTestBase
{
[TestMethod]
public void RunMultipleTestAssemblies()
[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void RunMultipleTestAssemblies(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');
this.InvokeVsTestForExecution(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue);
this.ValidateSummaryStatus(2, 2, 2);
}

[TestMethod]
public void RunMultipleTestAssembliesInParallel()
[Ignore]
[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void RunMultipleTestAssembliesInParallel(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.AcceptanceTests
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

/// <summary>
/// The custom data test method attribute.
/// </summary>
public class CustomDataTestMethodAttribute : TestMethodAttribute
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesomeness!

{
/// <summary>
/// Find all data rows and execute.
/// </summary>
/// <param name="testMethod">
/// The test Method.
/// </param>
/// <returns>
/// The <see cref="TestResult[]"/>.
/// </returns>
public override TestResult[] Execute(ITestMethod testMethod)
{
List<DataRowAttribute> dataRows = new List<DataRowAttribute>();

var net46Rows = testMethod.GetAttributes<NET46TargetFramework>(false);
if (net46Rows != null && net46Rows.Length > 0 && net46Rows[0].DataRows.Count > 0)
{
dataRows.AddRange(net46Rows[0].DataRows);
}

var netcoreappRows = testMethod.GetAttributes<NETCORETargetFramework>(false);
if (netcoreappRows != null && netcoreappRows.Length > 0 && netcoreappRows[0].DataRows.Count > 0)
{
dataRows.AddRange(netcoreappRows[0].DataRows);
}

if (dataRows.Count == 0)
{
return new TestResult[] { new TestResult() { Outcome = UnitTestOutcome.Failed, TestFailureException = new Exception(FrameworkMessages.NoDataRow) } };
}

return RunDataDrivenTest(testMethod, dataRows.ToArray());
}

/// <summary>
/// Run data driven test method.
/// </summary>
/// <param name="testMethod"> Test method to execute. </param>
/// <param name="dataRows"> Data Row. </param>
/// <returns> Results of execution. </returns>
internal static TestResult[] RunDataDrivenTest(ITestMethod testMethod, DataRowAttribute[] dataRows)
{
List<TestResult> results = new List<TestResult>();

foreach (var dataRow in dataRows)
{
TestResult result = testMethod.Invoke(dataRow.Data);

if (!string.IsNullOrEmpty(dataRow.DisplayName))
{
result.DisplayName = dataRow.DisplayName;
}
else
{
result.DisplayName = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DataDrivenResultDisplayName, testMethod.TestMethodName, string.Join(",", dataRow.Data));
}

results.Add(result);
}

return results.ToArray();
}
}

/// <summary>
/// The attribute defining runner framework, target framework and target runtime for net46.
/// </summary>
public class NET46TargetFramework : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="NET46TargetFramework"/> class.
/// </summary>
public NET46TargetFramework()
{
this.DataRows = new List<DataRowAttribute>(2);
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.CoreRunnerFramework, AcceptanceTestBase.DesktopTargetFramework, AcceptanceTestBase.CoreRunnerTargetRuntime));
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.DesktopRunnerFramework, AcceptanceTestBase.DesktopTargetFramework, AcceptanceTestBase.DesktopRunnerTargetRuntime));
}

/// <summary>
/// Gets or sets the data rows.
/// </summary>
public List<DataRowAttribute> DataRows { get; set; }
}

/// <summary>
/// The attribute defining runner framework, target framework and target runtime for netcoreapp1.*
/// </summary>
public class NETCORETargetFramework : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="NETCORETargetFramework"/> class.
/// </summary>
public NETCORETargetFramework()
{
this.DataRows = new List<DataRowAttribute>(4);
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.CoreRunnerFramework, AcceptanceTestBase.CoreTargetFramework, AcceptanceTestBase.CoreRunnerTargetRuntime));
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.DesktopRunnerFramework, AcceptanceTestBase.CoreTargetFramework, AcceptanceTestBase.DesktopRunnerTargetRuntime));
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.CoreRunnerFramework, AcceptanceTestBase.Core11TargetFramework, AcceptanceTestBase.CoreRunnerTargetRuntime));
this.DataRows.Add(new DataRowAttribute(AcceptanceTestBase.DesktopRunnerFramework, AcceptanceTestBase.Core11TargetFramework, AcceptanceTestBase.DesktopRunnerTargetRuntime));
}

/// <summary>
/// Gets or sets the data rows.
/// </summary>
public List<DataRowAttribute> DataRows { get; set; }
}
}
Loading