简体   繁体   中英

how to Change Attribute's parameter at runtime in Nunit

I want to change the assigned priority to test case at runtime

for ex:

[Test]
[Property("Priority", "change priority")]
public void TestCase1()
{
}

[Test]
[Property("Priority", "change priority")]
public void TestCase2()
{
}

so I want the value of priority which assigned to each test case to be dynamic and change based on specific condition

is it possible to make it dynamic

You can't do it that way. If you run all tests and then want to run those which failed, you have to get a list of the failed tests from TestResult.xml and set up your script to then run those tests. Since you don't say how you are running the tests in your pipeline, I can't tell you exactly how to do that, but for example, if you were using nunit3-console.exe , you might create a file containing the test names and use the --testlist option.

Whether or not it makes sense to rerun failed tests in your CI build is a different question but I tend to agree with @DavidG that it's a strange thing to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM