Is it possible to pass a value to the Fixtures on the EnableTestOrdering.cs file ?
Closed this issue · 15 comments
Hi Sebazzz,
Is there way to pass data to the test fixtures on the EnableTestOrdering.cs file?
Since the tests are now in proper test suites I wanted to pass a value through the test fixture for each test suite. This value would be a string value that would help in doing a lookup for the data sheet. This string value is matched to an enum value in a helper class that's matched to the corresponding row in the test data sheet.
Thanks!
Isn't the test generator feature in NUnit meant for this? This however runs after the test tree is constructed, this happens very early when loading an assembly into NUnit.
Thanks for your feedback. I haven't used that feature before but I've downloaded it and I'll see if it helps. I know params can be passed through the TestFixture and TestFixtureSource attribute, but I'm not sure if those attributes are legal on the EnableTestOrdering.cs file? If I placed that param on the cs file for that TestFixture each time that file is used, it would be limited to that one param even though the .cs file would be run in multiple test suites.
By the way, thanks for patience and help with answering my questions. My background is in the Java ecosystem so everything in the c# space has been new for me.
Just wanted to check in and see if the TestFixture and TestFixtureSource are acceptable attributes in the EnableTestOrdering.cs file or is there something similar within the NUnitTestOrdering library?
Thanks!
That's no problem. NUnitTestOrdering re-orders and groups the test by modifying the hierarchy. Existing NUnit attributes can still be used.
Still trying to figure this item out.
For the TestFixtures below, how would I pass one parameter through the Testfixtures below.
At the moment I have a tc_num ( a string value) that I would like to pass through each TestFixture below.
public sealed class CTAC_B_PR_TC01 : TestOrderingSpecification
{
public CTAC_B_PR_TC01()
{
}
protected override void DefineTestOrdering()
{
TestFixture<WEBP_BLDG_Contractor_Login>();
TestFixture<WEBP_PermitApplication_ApplyForNewBuilding>();
TestFixture<WEBP_PermitApplication_AddressLookUp_ExactValue_CLT>();
TestFixture<WEBP_PermitApplication_ApplicPages_CTAC_BLDG_Business_New>();
TestFixture<WEBP_BLDG_PermitApplication_Services_RequiredOnly>();
TestFixture<WEBP_BLDG_PermitApplication_SubTrades_Electrcial_PrimaryContractor>();
TestFixture<WEBP_BLDG_PermitApplication_SubTrades_Mechanical_PrimaryContractor>();
TestFixture<WEBP_BLDG_PermitApplication_SubTrades_Plumbing_PrimaryContractor_Last>();
TestFixture<WEBP_PermitApplication_BLDG_Applicant>();
TestFixture<WEBP_ePlansSubmittal_CTAC>();
}
protected override bool ContinueOnError => true;
Hi Sebazzz,
Just wanted to check in and see if there was any feedback?
Thanks!
@AutomationSifu Can you describe the bigger picture you are trying to achieve?
As far as I understand it now, you have a suit of tests, probably web automation tests, and based on an spreadsheet you would like to run multiple series of tests.
Hi Sebazz,
My apologies for the delay. I'm trying to pass a different piece of data to each suite of test fixtures set up in the EnableTestOrdering.cs. This piece of data is a test case id that I'm using to map the data to each suite of test fixtures.
I've updated my original code sample below to provide more detail:
public CTAC_B_PR_TC01(string tc_num1)
{
tc_num1 = "CTAC_B_PR_TC030";
Console.WriteLine("Values form EnableTest file: " + tc_num1);
}
public CTAC_B_PR_TC01() : this(null) { }
protected override void DefineTestOrdering()
{
TestFixture<WEBP_BLDG_Contractor_Login>();
}
protected override bool ContinueOnError => true;
For this example I want the value of tc_num1 to be passed to the following testFixture: WEBP_BLDG_Contractor_Login. It appears that this is something that should be very straight forward but for some reason it's not working. I think I'm missing something very minor to accomplish this goal.
I understand where you are coming from. In essence, the test tree needs to be duplicated based on some input. This is currently not possible in this library, but it is do-able.
A few notes:
This is from a debuggability standpoint hard for the user. Normally NUnit assumes that no user-defined code runs when the tests are discovered. If something happens, it will be hard to debug why with the default NUnit options for debugging because NUnit attaches the debugger after the test discovery has been done. This even applies in command-line mode.
We need to determine how the API will look and how users will write code to interact with it. There are a few possibilities, but the most logical would be to let the TestOrderingSpecification
have a method that gives back one or more test items.
For instance: IEnumerable<TestHierarchyArgument> GetTestArguments()
. TestOrderingArgument
would be a struct of string Name; object Argument;
. The Name
would be used as a root for duplicating the test tree.
Thanks that helps to know that the idea would add value to the library in the future.
One route I've also considered taking as a work-around is pulling in the TestContext.CurrentContext.Test.FullName value at run time from NUnit.
I've changed this comment to stay within the scope of this library.
Is there a way to subscribe or be informed in case you do decide to implement a feature of this type?
Hi @Sebazzz
Does the NUnitTestOrdering library write any data to NUnit?
- I ask because in the NUnit Gui (TestCentric) there is a Full Name value and I wanted to know if that value is populated by NUnit or the NUnitTestOrdering library.
I've included a screenshot below for reference:
Yes, the test hierarchy is rebuild based on the ordering scheme. The FullName value reflects the full path of the test or test fixture in the hierarchy. It is what you would use if specifying a filter on the command line.
Thanks, closing this item.