Skip to content

Commit

Permalink
Issue 1197, prepare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisTerje committed Sep 2, 2024
1 parent 80ace95 commit 0e5cf86
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 42 deletions.
20 changes: 10 additions & 10 deletions src/NUnit.TestAdapter.Tests.Acceptance/ConsoleOutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class ConsoleOutTests : CsProjAcceptanceTests
{
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Issue774.cs", @"
workspace.AddFile("Issue774.cs", @"
using System;
using NUnit.Framework;
Expand All @@ -30,23 +30,23 @@ public void Test2()
}
}
}");
}
}

protected override string Framework => Frameworks.NetCoreApp31;

[Test, Platform("Win")]
public void DotNetTest()
{
var workspace = Build();
var results = workspace.DotNetTest("", true, true, TestContext.WriteLine);
Verify(2, 2, results);
}
var workspace = Build();
var results = workspace.DotNetTest("", true, true, false, TestContext.WriteLine);
Verify(2, 2, results);
}

[Test, Platform("Win")]
public void VsTest()
{
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", VsTestFilter.NoFilter);
Verify(2, 2, results);
}
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", VsTestFilter.NoFilter);
Verify(2, 2, results);
}
}
54 changes: 54 additions & 0 deletions src/NUnit.TestAdapter.Tests.Acceptance/ExplicitIgnoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

public class ExplicitIgnoreTests : CsProjAcceptanceTests
{
/// <summary>
/// Related to Issue1197. Since we use a category filter, the test with Explicit only should be executed, but not the one with Ignore.
/// https://github.com/nunit/nunit3-vs-adapter/issues/1197.
/// </summary>
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Tests.cs", @"
using NUnit.Framework;
namespace TestProject1
{
[TestFixture, Category(""MyCustomCategory"")]
[Explicit]
[Ignore(""Ignoring"")]
public class MyTestClass
{
[Test]
public void MyTest()
{
Assert.Pass();
}
}
[TestFixture, Category(""MyCustomCategory"")]
[Explicit]
public class AnotherTestClass
{
[Test]
public void AnotherTest()
{
Assert.Pass();
}
}
}
");
}

protected override string Framework => Frameworks.Net80;

[TestCase("TestCategory=MyCustomCategory", 1, 2)]
public void Filter_DotNetTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, true, TestContext.WriteLine);
Verify(executed, total, results);
}
}
30 changes: 15 additions & 15 deletions src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class FilterTests : CsProjAcceptanceTests
{
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Tests.cs", @"
workspace.AddFile("Tests.cs", @"
using NUnit.Framework;
namespace Filter
Expand All @@ -34,7 +34,7 @@ public void Bar()
}
}
}");
}
}

protected override string Framework => Frameworks.NetCoreApp31;

Expand All @@ -51,10 +51,10 @@ public void Bar()
// [TestCase(@"FullyQualifiedName~Foo", 1, 1)]
public void Filter_DotNetTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, TestContext.WriteLine);
Verify(executed, total, results);
}
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, false, TestContext.WriteLine);
Verify(executed, total, results);
}

[Test, Platform("Win")]
[TestCase(NoFilter, 2, 3)]
Expand All @@ -65,10 +65,10 @@ public void Filter_DotNetTest(string filter, int executed, int total)
[TestCase("TestCategory=XXXX", 0, 0)]
public void Filter_VSTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", new VsTestTestCaseFilter(filter));
Verify(executed, total, results);
}
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", new VsTestTestCaseFilter(filter));
Verify(executed, total, results);
}

[Test, Platform("Win")]
[TestCase(NoFilter, 2, 3)]
Expand All @@ -83,9 +83,9 @@ public void Filter_VSTest(string filter, int executed, int total)
// [TestCase("test=~Foo", 1, 1)]
public void Filter_DotNetTest_NUnitWhere(string filter, int executed, int total)
{
var workspace = Build();
var nunitWhere = $"NUnit.Where={filter}";
var results = workspace.DotNetTest(nunitWhere, true, true, TestContext.WriteLine);
Verify(executed, total, results);
}
var workspace = Build();
var nunitWhere = $"NUnit.Where={filter}";
var results = workspace.DotNetTest(nunitWhere, true, true, false, TestContext.WriteLine);
Verify(executed, total, results);
}
}
26 changes: 13 additions & 13 deletions src/NUnit.TestAdapter.Tests.Acceptance/FixtureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class FixtureTests : CsProjAcceptanceTests
{
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Issue918.cs", @"
workspace.AddFile("Issue918.cs", @"
using System;
using NUnit.Framework;
Expand All @@ -33,7 +33,7 @@ public static class FixtureSources
}
}");

workspace.AddFile("Issue869.cs", @"
workspace.AddFile("Issue869.cs", @"
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -59,7 +59,7 @@ public void SomeRandomTest()
}
}");

workspace.AddFile("Issue884.SetupFixture.cs", @"
workspace.AddFile("Issue884.SetupFixture.cs", @"
using NUnit.Framework;
namespace NUnitTestAdapterIssueRepro
Expand All @@ -78,7 +78,7 @@ public void OneTimeTeardown()
}
}
}");
workspace.AddFile("Issue884.Tests.cs", @"
workspace.AddFile("Issue884.Tests.cs", @"
using NUnit.Framework;
namespace NUnitTestAdapterIssueRepro
Expand All @@ -105,7 +105,7 @@ public void Test()
}
}
}");
}
}

protected override string Framework => Frameworks.NetCoreApp31;

Expand All @@ -115,19 +115,19 @@ public void Test()
[TestCase("TestCategory=918", 1, 1)]
public void DotNetTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, TestContext.WriteLine);
Verify(executed, total, results);
}
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, false, TestContext.WriteLine);
Verify(executed, total, results);
}

[Test, Platform("Win")]
[TestCase("TestCategory=869", 2, 2)]
[TestCase("TestCategory=884", 3, 3)]
[TestCase("TestCategory=918", 1, 1)]
public void VsTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", new VsTestTestCaseFilter(filter));
Verify(executed, total, results);
}
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", new VsTestTestCaseFilter(filter));
Verify(executed, total, results);
}
}
2 changes: 1 addition & 1 deletion src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void VsTestTests(string filter, int executed, int total)
public void DotnetTestCases(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, TestContext.WriteLine);
var results = workspace.DotNetTest(filter, true, true, false, TestContext.WriteLine);
Verify(executed, total, results);
}
}
2 changes: 1 addition & 1 deletion src/NUnit.TestAdapter.Tests.Acceptance/PropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Test2()
public void DotNetTest(string filter, int executed, int total)
{
var workspace = Build();
var results = workspace.DotNetTest(filter, true, true, TestContext.WriteLine);
var results = workspace.DotNetTest(filter, true, true, false, TestContext.WriteLine);
Verify(executed, total, results);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public void DotNetBuild(bool noRestore = false)
/// <param name="noBuild">if you run MSBuild or dotnet build first, set to false.</param>
/// <param name="verbose">Set NUnit verbosity to 5, enables seing more info from the run in StdOut.</param>
/// <returns>VSTestResults.</returns>
public VSTestResult DotNetTest(string filterArgument = "", bool noBuild = false, bool verbose = false, Action<string> log = null)
public VSTestResult DotNetTest(string filterArgument = "", bool noBuild = false, bool verbose = false, bool debug = false, Action<string> log = null)
{
using var tempTrxFile = new TempFile();
bool inNUnitSection = false;

var dotnettest = ConfigureRun("dotnet")
.Add("test")
Expand All @@ -79,13 +80,26 @@ public VSTestResult DotNetTest(string filterArgument = "", bool noBuild = false,
else if (hasNUnitWhere)
{
dotnettest.Add("--").Add(filterArgument);
inNUnitSection = true;
}
if (verbose)
{
if (!hasNUnitWhere)
if (!inNUnitSection)
{
dotnettest.Add("--");
inNUnitSection = true;
}
dotnettest.Add("NUnit.Verbosity=5");
}
if (debug)
{
if (!inNUnitSection)
{
dotnettest.Add("--");
inNUnitSection = true;
}
dotnettest.Add("NUnit.Debug=true");
}
log?.Invoke($"\n{dotnettest.ArgumentsAsEscapedString}");
var result = dotnettest.Run(throwOnError: false);

Expand Down

0 comments on commit 0e5cf86

Please sign in to comment.