Closed FabianOswald-WolfSystem closed 1 month ago
What TestCaseSource
means?
Please add some description with a sample.
Of course, this would be a sample test:
public static IEnumerable<string> Names = new string[] { "Foo1", "Foo2", "Foo3" };
[TestCaseSource(nameof(Names))]
public void Foo(string name)
{
Console.WriteLine(name);
Assert.True(true);
}
https://docs.nunit.org/articles/nunit/writing-tests/attributes/testcasesource.html
Interesting, is basically a compact TestCase
with multiple source.
Never used this TestCaseSource
and looks great, lets add support for that.
That would be really helpful. We run a test for all our Revit families, this takes about an hour. During this time I do not see any console output, as this is intercepted by NUnit and then output in the test result. In addition, the test is currently aborted after 10 minutes, I have not yet found a reason for this. With TestCaseSource I can run a separate test for each family.
What kinda of test your are doing in the family, open and validating some parameters?
Actually I have a custom version of the NUnit to run the tests inside Revit, that's the reason the TestCaseSource
does not work by default, and I pretty sure the console output is show in the test result, for me is the best feature 😀
The 10 minutes
is hard coded, need to expose a option for that.
We need to support Revit families for multiple versions of Revit. We open the families and then save them again after they have been updated by Revit. This allows the end user to use the family without the update process. Parameters are also filled in. In future, the families may be translated into several languages. I also find it useful that the console output is summarized, especially when tests are executed in parallel, because this is the only way to assign which console output refers to which test. Unfortunately, in NUnit 3.13.3 there is no way to avoid this.
We need to support Revit families for multiple versions of Revit. We open the families and then save them again after they have been updated by Revit. This allows the end user to use the family without the update process. Parameters are also filled in. In future, the families may be translated into several languages.
Nice, I kinda need to do the same thing with some of my families just to remove the update process in Revit to make the plugin more smooth.
Are you update all the families inside a folder or using the TestCase
for selecting the family file name?
We have all families and test cases in one repository. All families are in one folder and are all updated together in one test. However, as soon as TestCaseSource is implemented, I will use one TestCase per family.
We have all families and test cases in one repository. All families are in one folder and are all updated together in one test. However, as soon as TestCaseSource is implemented, I will use one TestCase per family.
Could you explain how you gonna do that using TestCaseSource
?
I suppose TestCaseSource
gonna select each file name in a folder on the fly.
If you could share a sample would be really useful.
public static string[] GetFileNames()
{
return Directory.GetFiles(@"C:\Users\fabian.oswald\Downloads");
}
[TestCaseSource(nameof(GetFileNames))]
public void TestFile(string fileName)
{
Console.WriteLine(fileName);
Assert.True(true);
}
@FabianOswald-WolfSystem I prerelease a version to support TestCaseSource
.
Should support the basic stuff, here is a sample. If you could give a quick test and feedback I appreciated.
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace RevitTest.Sample
{
public class Tests_Files
{
public static IEnumerable<string> GetFileNames()
{
var folder = Directory.GetCurrentDirectory();
return Directory.GetFiles(folder, "*RevitTest*.dll").Select(Path.GetFileName);
}
[TestCaseSource(nameof(GetFileNames))]
public void TestFile(string fileName)
{
Console.WriteLine(fileName);
Assert.True(true);
}
public static string[] GetRevitFileNames()
{
var downloadFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
return Directory.GetFiles(downloadFolder, "*.rvt");
}
[TestCaseSource(nameof(GetRevitFileNames))]
public void TestRevitFile(string fileName)
{
Console.WriteLine(fileName);
Assert.True(true);
}
}
}
Thank you very much for the quick implementation. I have tested it and it works perfectly.
Now the version 1.5.0 have support for the TestCaseSource
Support
TestCaseSourceAttribute
to run test cases with a custom source.NUnit API Reference
Sample
Edited by @ricaun