microsoft / testfx

MSTest framework and adapter
MIT License
737 stars 254 forks source link

Getting DataSource object right is very difficult #1054

Open nohwnd opened 2 years ago

nohwnd commented 2 years ago

Description

I was trying to get the new UI in VS for data driven tests. And getting the object for the data source to correctly serialize is so painful.

My contains other objects and getting it to work took me a lot of time.

Is there any additional guidance on this? Or a method that can check if the type is eligible for the new UI?

From what I see:

e.g. This works:

[Serializable]
public class OtherInfo : OtherInfoBase { 
}

[Serializable]
public class OtherInfoBase { 
    public string Name {get; set;}
}

[Serializable]
public class RunnerInfo { 
    public string Name {get; set;}
    public OtherInfo {get; set;}
}

BUT making the RunnerInfo use the Base class, it only works when we assign the BaseClass itself, but not if we create OtherInfo and assign it:

[Serializable]
public class OtherInfo : OtherInfoBase { 
}

[Serializable]
public class OtherInfoBase { 
    public string Name {get; set;}
}

[Serializable]
public class RunnerInfo { 
    public string Name {get; set;}
    public OtherInfoBase {get; set;}
}
Evangelink commented 1 year ago

@nohwnd What kind of data source are you referring to? Could you provide a more complete example?

ghost commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 10 days of this comment.

nohwnd commented 1 year ago

DataSource like the one here: https://github.com/microsoft/vstest/blob/3fac63690f8cd14e2681470639b15c527c3d09ff/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs#L21

Once your parameter is not a primitive type (RunnerInfo in the case above) it gets really difficult to make sure MSTest will expand it to multiple test cases using the new top level expansion. You need to balance all the things listed above.

stan-sz commented 4 months ago

@Evangelink - Is this something that can be checked with a MSTest analyzer?

nohwnd commented 4 months ago

After working for a while on the codebase I think this mostly boils down to the serializer that is used. It would be pretty difficult to enforce the rules by analyzer, and custom data sources are imho not that used to warrant that investment.