Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Bulk update of Nunit test results in C#


#1

I want to update my NUnit tests in bulk,tried with below code snippet

string[] results = new string[]{"{“results”:[" +
"{“case_id”:“1”,“status_id”:“5”,“comment”, “This test failed”}," +
"{“case_id”:“2”,“status_id”:“5”,“comment”, “This test failed”}," +
"{“case_id”:“3”,“status_id”:“1”,“comment”, “This test failed”}" +
"]}"};
Dictionary<string,string[]> al=new Dictionary<string,string[]>();
al.Add(“results”,results);
JObject r = (JObject)client.SendPost(“add_results_for_cases/11”, al); //Here I am using a hardcoded test run id and test id.

But i am getting error saying "TestRail API returned HTTP 400 (“Field :results is not a valid array.”),please help me to rectify it.


#2

Hi @arunhm,

Thanks for your posting! Sure, happy to help. You would need to format this using C# data structures such as array and dictionaries instead of using strings. SendPost would then serialize this to a JSON string. So, results should be a array or List object and each item should be a dictionary with case_id, status_id etc. attributes.

I hope this helps!

Cheers,
Tobias