Relative Content

Tag Archive for c#xunit

Static variables get in a way of unit testing with WebApplicationFactory in xUinit

I have a WebApplicationFactory which makes a call to MongoDB.Bson.Serialization.BsonClassMap.RegisterClassMap, which is fine when my first test run, but the second test crashes with error because this method was already called with similar args, because it’s state is preserved in static field. I can’t alter the code that causes the error.

How to mock static interface in xunit c#

I have performanceLogger class where I need to set IMyTelemetryClient. we are mocking the IMyTelemetryClient in the test even though it’s value is null and throwing invalidoperation exception. below is the class and xunit.