Skip to content

Commit

Permalink
Merge pull request #28 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 1.4.0 - Support `TestCaseSourceAttribute`
  • Loading branch information
ricaun authored Sep 19, 2024
2 parents fb9f0c4 + 02876cf commit d80c014
Show file tree
Hide file tree
Showing 20 changed files with 456 additions and 212 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
SignFile: ${{ secrets.SIGN_FILE }}
SignPassword: ${{ secrets.SIGN_PASSWORD }}
InstallationFiles: ${{ secrets.INSTALLATION_FILES }}
NugetApiUrl: ${{ secrets.NUGET_API_URL }}
NugetApiKey: ${{ secrets.NUGET_API_KEY }}
13 changes: 13 additions & 0 deletions Build/.nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"type": "boolean",
"description": "Shows the execution plan (HTML)"
},
"PreReleaseFilter": {
"type": "array",
"items": {
"type": "string"
}
},
"Profile": {
"type": "array",
"description": "Defines the profiles to load",
Expand Down Expand Up @@ -99,8 +105,10 @@
"Build",
"Clean",
"Compile",
"GitPreRelease",
"GitRelease",
"Pack",
"PrePack",
"Release",
"Sign",
"Test"
Expand All @@ -120,8 +128,10 @@
"Build",
"Clean",
"Compile",
"GitPreRelease",
"GitRelease",
"Pack",
"PrePack",
"Release",
"Sign",
"Test"
Expand All @@ -137,6 +147,9 @@
"TestResults": {
"type": "boolean"
},
"UnlistNuget": {
"type": "boolean"
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
Expand Down
3 changes: 2 additions & 1 deletion Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using ricaun.Nuke;
using ricaun.Nuke.Components;

class Build : NukeBuild, IPublishPack, ITest
class Build : NukeBuild, IPublishPack, ITest, IPrePack
{
bool IPack.UnlistNuget => true;
public static int Main() => Execute<Build>(x => x.From<IPublishPack>().Build);
}
2 changes: 1 addition & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>.</NukeRootDirectory>
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.0] / 2024-09-11
### Features
- Support `TestCaseSourceAttribute` with `IEnumerable` and `object[]` parameters. (Fix: #27)
### Updated
- Update to support target `net48` and `net8.0`.
- Update `TestAttributeService` to convert `TestCaseSourceAttribute` to `TestCaseAttribute`.
- Update `TestCaseSourceService` to support multiple parameters.
- Update `TestCaseSourceService` to support `TestCaseData`.
- Update `GetTestFullNames` to find tests using `ExportedTypes`.
- Update `RunTests` to have `ExportedTypes` options.
### Added
- Add `TestCaseSourceService` with `TestCaseSourceAttribute` implementation.
### Tests
- Add `TestsCaseSource` sample tests.
- Add `InternalTests` to test `ExportedTypes` only.

## [1.3.1] / 2023-09-28
### Features
- Enable to work with `net5.0` or greater
Expand Down Expand Up @@ -228,6 +244,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Test with Console Output

[vNext]: ../../compare/1.0.0...HEAD
[1.4.0]: ../../compare/1.3.1...1.4.0
[1.3.1]: ../../compare/1.3.0...1.3.1
[1.3.0]: ../../compare/1.2.9...1.3.0
[1.2.9]: ../../compare/1.2.8...1.2.9
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.4.0</Version>
</PropertyGroup>
</Project>
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

ricaun.NUnit is a package to manage the Load and Test assemblies using the [NUnit](https://www.nuget.org/packages/NUnit/) Attributes as patterns.

[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](../..)
[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](https://github.com/ricaun-io/ricaun.NUnit)
[![Nuke](https://img.shields.io/badge/Nuke-Build-blue)](https://nuke.build/)
[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Build](../../actions/workflows/Build.yml/badge.svg)](../../actions)
[![.NET Framework 4.5](https://img.shields.io/badge/.NET%20Framework%204.5-blue.svg)](../..)
[![.NET Standard 2.0](https://img.shields.io/badge/-.NET%20Standard%202.0-blue)](../..)
[![.NET 5.0](https://img.shields.io/badge/-.NET%205.0-blue)](../..)
[![Build](https://github.com/ricaun-io/ricaun.NUnit/actions/workflows/Build.yml/badge.svg)](https://github.com/ricaun-io/ricaun.NUnit/actions)
[![NUnit](https://img.shields.io/badge/NUnit-3.13.3-blue)](https://www.nuget.org/packages/NUnit)
[![nuget](https://img.shields.io/nuget/v/ricaun.NUnit?logo=nuget)](https://www.nuget.org/packages/ricaun.NUnit)

## Features
```C#
Expand All @@ -26,6 +24,7 @@ The tests use the [NUnit](https://www.nuget.org/packages/NUnit/) Attributes `[Te
* The attribute `[Order]` makes the order that the test will run in.
* The attribute `[Explicit]` works only if the `Filter` is enable.
* The attribute `[TestCase]` disable the `Optional Parameters`
* The attribute `[TestCaseSource]` disable the `Optional Parameters`

```C#
public class TestSampleClass
Expand Down Expand Up @@ -88,6 +87,13 @@ public class TestSampleClass
{
Assert.True(i > 0);
}

public static int[] CasesSource = new[] { 1, 2, 3 };
[TestCaseSource(nameof(CasesSource))]
public void CasesSourceTest(int i)
{
Assert.True(i > 0);
}
}
```

Expand Down Expand Up @@ -208,12 +214,12 @@ public class TestParameterClass : IDisposable

## Release

* [Latest release](../../releases/latest)
* [Latest release](https://github.com/ricaun-io/ricaun.NUnit/releases/latest)

## License

This project is [licensed](LICENSE) under the [MIT Licence](https://en.wikipedia.org/wiki/MIT_License).
This project is [licensed](LICENSE) under the [MIT License](https://en.wikipedia.org/wiki/MIT_License).

---

Do you like this project? Please [star this project on GitHub](../../stargazers)!
Do you like this project? Please [star this project on GitHub](https://github.com/ricaun-io/ricaun.NUnit/stargazers)!
19 changes: 19 additions & 0 deletions SampleTest.Tests/InternalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NUnit.Framework;

namespace SampleTest.Tests
{
internal class InternalTests
{
[Test]
public void PublicTest() { }

#if DEBUG
// NUnit throw 'Method is not public'
[Test]
internal void InternalTest() { }

[Test]
private void PrivateTest() { }
#endif
}
}
77 changes: 77 additions & 0 deletions SampleTest.Tests/TestsCaseSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;

namespace SampleTest.Tests
{
public class TestsCaseSource
{

public static int[] CasesSource = new[] { 1, 2, 3 };
[TestCaseSource(nameof(CasesSource))]
public void CasesSourceTest(int i)
{
Assert.True(i > 0);
}


static IEnumerable<int> CasesSourceMethod()
{
yield return 1;
yield return 2;
yield return 3;
}
[TestCaseSource(nameof(CasesSourceMethod))]
public void CasesSourceMethodTest(int i)
{
Assert.True(i > 0);
}

static IEnumerable<int> CasesSourceMethodWithParameters(int start, int count)
{
for (int i = 0; i < count; i++)
{
yield return start + i;
}
}

[TestCaseSource(nameof(CasesSourceMethodWithParameters), new object[] { 1, 4 })]
public void CasesSourceMethodWithParametersTest(int i)
{
Assert.True(i > 0);
}

public class AnotherClass
{
public static object[] CasesSource =
{
new object[] { 1, 2, 3 },
new object[] { 2, 3, 4 },
new object[] { 3, 4, 5 }
};
}
[TestCaseSource(typeof(AnotherClass), nameof(AnotherClass.CasesSource))]
public void CasesSourceAnotherClassTest(int i, int j, int k)
{
Assert.True(i > 0);
Assert.True(j > 0);
Assert.True(k > 0);
}

public static IEnumerable TestCaseDatas
{
get
{
yield return new TestCaseData(0).Returns(false);
yield return new TestCaseData(1).Returns(true);
yield return new TestCaseData(2).Returns(true);
yield return new TestCaseData(3).Returns(true);
}
}
[TestCaseSource(nameof(TestCaseDatas))]
public bool CasesSourceTestCaseDataTest(int i)
{
return i > 0;
}
}
}
24 changes: 23 additions & 1 deletion ricaun.NUnit.Tests/NUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@ public void TestAssembly_Service()
Assert.IsNotEmpty(typeMethods);
}

[TestCase("InternalTests")]
public void TestAssembly_Service_UseExported(string testNameNotPublic)
{
var service = new Services.TestAssemblyService(pathFile);
var testFullNames = service.GetTestFullNames();
var exportedTestFullNames = service.GetTestFullNames(true);

Assert.IsNotEmpty(testFullNames);
Assert.IsNotEmpty(exportedTestFullNames);

Console.WriteLine($"Test Count: {testFullNames.Count()}");
Console.WriteLine($"Exported Count: {exportedTestFullNames.Count()}");

var containsTestName = testFullNames.Any(e => e.Contains(testNameNotPublic));
var notContatinsTestName = exportedTestFullNames.Any(e => e.Contains(testNameNotPublic));

Assert.IsTrue(containsTestName);
Assert.IsFalse(notContatinsTestName);
}

[Test]
public void TestAssembly_AbstractTest()
{
Expand Down Expand Up @@ -303,7 +323,9 @@ public void TestAssembly_Parameters()
[TestCase("*.MultipleTest.*", 2)]
[TestCase("*AbstractTest?*", 4)]
[TestCase("*Abstract*", 4)]
[TestCase("*", 60)]
[TestCase("*.TestsCaseSource.*", 17)]
[TestCase("*.InternalTests.*", 1)]
[TestCase("*", 78)]
public void TestAssembly_Filter(string testName, int numberOfTests)
{
TestEngineFilter.Add(testName);
Expand Down
45 changes: 45 additions & 0 deletions ricaun.NUnit.Tests/Revit/RevitRunTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;

namespace ricaun.NUnit.Tests.Revit
{
public class RevitRunTests
{
private string GetPathFile(string filePath)
{
var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return Path.Combine(location, filePath);
}

[TestCase("Revit\\RevitTest.dll")]
[TestCase("Revit\\RevitTestDB.dll")]
public void GetTests(string pathFile)
{
var names = TestEngine.GetTestFullNames(GetPathFile(pathFile));

foreach (var name in names)
Console.WriteLine($"{name}");

foreach (var ex in TestEngine.Exceptions)
{
Console.WriteLine($"Exception: {ex.Message}");
}
}

[TestCase("Revit\\RevitTest.dll")]
[TestCase("Revit\\RevitTestDB.dll")]
public void RunTests(string pathFile)
{
var testAssemblyModel = TestEngine.TestAssembly(GetPathFile(pathFile));

Console.WriteLine(testAssemblyModel.AsString());

foreach (var ex in TestEngine.Exceptions)
{
Console.WriteLine($"Exception: {ex.Message}");
}
}
}
}
6 changes: 1 addition & 5 deletions ricaun.NUnit.Tests/ricaun.NUnit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;net6.0</TargetFrameworks>
<TargetFrameworks>net45;net48;net6.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
Expand Down Expand Up @@ -32,10 +32,6 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<!--
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" IncludeAssets="build; compile" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" IncludeAssets="build; compile" PrivateAssets="All" />
-->
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion ricaun.NUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{09BFC454-8566-456C-83F0-80E77F05BA14}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
Directory.Build.props = Directory.Build.props
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -18,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ricaun.NUnit.Tests", "ricau
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleTest.Tests", "SampleTest.Tests\SampleTest.Tests.csproj", "{A3F8A436-6412-4092-9807-7DF6CF7E176F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTest", "SampleTest\SampleTest.csproj", "{C9C3CE2D-3D95-49A4-9733-152D38646759}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleTest", "SampleTest\SampleTest.csproj", "{C9C3CE2D-3D95-49A4-9733-152D38646759}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Loading

0 comments on commit d80c014

Please sign in to comment.