It'd be quicker and far easier to create a class that reads all the test cases from your file and creates TestCaseData
objects (see this page). You can set the name of each test case via the Name
property on the TestCaseData
.
Can I create a unit test at runtime in C# using reflection?
-
26-06-2023 - |
Pregunta
I have a scenario where I'm needing to create tests at runtime based on a script.
I have a set of scenarios defined in a text file that need to be interpreted and each one should be run as an unit test under nunit.
I've created a general IntegrationTestRunner to read the data and run one big test for each scenario that is defined. This works fine.
However, it seems to make good sense that each scenario should be it's own unit test.
Is there a way to dynamically create nunit-based unit tests at runtime using reflection?
Thank you!
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow