I'm doing integration tests for a REST API, which are built that way:
[Test, TestCaseSource(nameof(Data))]
public async Task New_Transaction()
{
var client = new HttpClient();
//Client headers and etc here...
var request = new StringContent(JsonConvert.SerializeObject(Data), Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, request);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
var resultObj = JsonConvert.DeserializeObject<Response<object>>(result);
if (!resultObj.HasError)
Console.WriteLine(JObject.Parse(result));
else
Assert.Fail($"{resultObj.ErrorCode} - {resultObj.Error}");
}
Test data must be an object built based on some models and must be passed to serialization, but to avoid redundancy and keep it centralized on my structure, I found that using the TestData parameter could work at this approach, but I'm having a problem in the Test Explorer, as it's not showing properly and it always shows a "blank" test that is not run.
Test data is mounted like this:
private static IEnumerable Data
{
get
{
yield return new TestCaseData(new Transaction<BankSlip>
{
IsSandbox = true,
Application = "TEST 1",
Vendor = "TEST 1 ",
Reference = "INTEGRATION TEST CASE 1",
Customer = new Customer()
//rest of the object of test case 2
})
.SetName("TEST 1")
.SetDescription("22222222222222222222.");
yield return new TestCaseData(new Transaction<BankSlip>
{
IsSandbox = true,
Application = "TEST 2",
Vendor = "TEST 2",
Reference = "INTEGRATION TEST CASE 2",
Customer = new Customer()
//rest of the object of test case 2
})
.SetName("TEST 2")
.SetDescription("22222222222222222222.");
}
}
Like this example, both test cases works fine, but Test Explorer shows the main test, which doesn't run and keeps untouched. That would not be a problem, but it does mess with the reports later...
Is there any other way that I can use this same generic structure and send complex objects like this in the same test, but keeping, for example, the same naming for all of them or avoiding this one that doesn't run?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire