问题
When I execute my all controllers mock test cases then some of the test cases get failed but they got pass individually.
I used Dispose() where I was using the same variable thought the unit test but still, it does not fix.
In my project, I made a common setup Example: AbcMock
public class AbcMock
{
public static Mock<IAbcMock> abcMock;
public static void Setup()
{
abcMock = new Mock<IAbcMock>();
abcMock.Setup(x => x.GetAll(It.IsAny<Guid>())).Returns(1);
}
}
Then i have made common setup to all services in another file let's say baseController.cs has following setup
public Mock<IAbcMock> abcMock ;
abcMock = AbcMock.abcMock;
AbcMock.Setup();
My actul test controller
public class AbcMockTestController : baseController
{
AbcService abcService ;
public ClaimExpertRolesMockTestController()
{
abcService = new AbcService (foo.Object, boo.Object);
}
[Fact]
public void GetAll_Passing_Valid_Data()
{
abcMock.Setup(x => x.GetAll(It.IsAny<Guid>())).Returns(2);
var result = abcService.GetAll(Guid.NewGuid());
Assert.Equal(ProcessStatusEnum.Success, result.Status);
}
[Fact]
public void GetAll_Passing_Valid_Data()
{
abcMock.Setup(x => x.GetAll(It.IsAny<Guid>())).Returns(3);
var result = abcService.GetAll(Guid.NewGuid());
Assert.Equal(ProcessStatusEnum.Success, result.Status);
}
}
This is my setup for my PROD code. After reading much article i got to know that making my mock object static is making mi issue because of that my test case is getting passed indivisually but failling after running all. So, any suggestions how can I resolve my issue without changing my code much?
来源:https://stackoverflow.com/questions/56865435/why-my-few-test-case-get-failed-after-running-all-controller-and-pass-individu