Unit Test, TestInitialize alternative in xUnit
Hello guys, I read that [TestInitialize] is used in MSTest to initialize an object. My first question is why should we initialize it? I mean, it seems that we build an entire method to initialize it, why not initializing it in the test cases?
Second thing, when each test cases is executed, the TestInitialize attribute creates a new instance for each case? The idea is we don't want shared data to affect our result?
I read a bit and came across how we can mimic TestInitialize in xUnit:
I write something like this. Can anyone confirm whether the idea is correct please.
Also, notice that we implement the IDisposable, why is it necessary here?
Second thing, when each test cases is executed, the TestInitialize attribute creates a new instance for each case? The idea is we don't want shared data to affect our result?
I read a bit and came across how we can mimic TestInitialize in xUnit:
I write something like this. Can anyone confirm whether the idea is correct please.
Also, notice that we implement the IDisposable, why is it necessary here?