publicclassSomeClassTest:BaseTest,IDisposable{publicvoidDispose(){_context.Database.EnsureDeleted();}[Fact]publicasyncTaskSomeTest(){// Here you have access to your _context as usual// Arrange// Act// Assert}}
I do like this approach, you can also use the test framework 'setup' method (in XUnit it's just the class constructor).
Personally, though, if I was going down this kind of path, I'd probably put the set-up into a static helper method, rather than using inheritance. IMHO it gives better readability to the test.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have used a different approach, not sure what are your thoughts on it:
Then in my tests, I inherit from that base class:
I do like this approach, you can also use the test framework 'setup' method (in XUnit it's just the class constructor).
Personally, though, if I was going down this kind of path, I'd probably put the set-up into a static helper method, rather than using inheritance. IMHO it gives better readability to the test.