Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In these days I'm trying to understand how xUnit tests work and, in particular, I discovered that there are 3 ways to pass data as parameters in order to test class methods (InlineData, ClassData and MemberData). But here Is my issue: is there any chance to get these data from an external file? (For example a Json file) I wasn't unable to find enough material about this topic, thanks for the attention!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
507 views
Welcome To Ask or Share your Answers For Others

1 Answer

xUnit has been designed to be extensible, i.a. via the DataAttribute.

InlineData, ClassData and MemberData all derive from DataAttribute, which you can extend yourself to create a custom data source for a data theory, in which you may read from you external file and use e.g. Json.NET to deserialize your data.

User Sock wrote about this in his blog regarding JSON, as you mentioned:

Related question with data from CSV file: How to run XUnit test using data from a CSV file

And here are two xUnit samples:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...