jeudi 19 juillet 2018

Using custom types for parameterized MSTests

I'm creating unit tests, and I'm wanting to create parameterized tests using custom types (like a dto).

I'm wanting to do something like this:

[TestMethod]
[DataRow(new StudentDto { FirstName = "Leo", Age = 22 })]
[DataRow(new StudentDto { FirstName = "John" })]
public void AddStudent_WithMissingFields_ShouldThrowException(StudentDto studentDto) {
    // logic to call service and do an assertion
}

  1. Is this something that you can do? I'm getting an error that says "An Attribute argument must be a constant expression..." I think I saw somewhere that attributes can only take primitive types as arguments?
  2. Is this the wrong approach? Should I just pass in the properties and create the dto within the test?

Aucun commentaire:

Enregistrer un commentaire