I'm new to JustMock as well as Unit Testing. I have a simple logic class with methods like Add, Delete, DeleteAll, GetAll, GetByID, ... I really don't think this should be tested using JustMock, simply because there is not much code (such as some other methods called inside each logic), each method simply uses an internal DbContext
(EF) to do the job. So if mocking and bypassing the actual implementation (the code done by EF with DbContext
), how could that test be considered as passed?
Here is an example which I think does not make much sense to me, the mock simply uses a local list and tests against that, if the mocking framework can mock successfully, there is no chance for the test to fail. It means the code seems to test the mocking framework (to see if it mocks OK) rather than test my code:
//Arrange
var someLogic = Mock.Create<SomeLogic>();
var e = new SomeEntity();
var list = new List<SomeEntity>();
var expectedResult = 1;
Mock.Arrange(() => someLogic.Add(e)).DoInstead(() => list.Add(e));
//Act
someLogic.Add(e);
//Assert
Assert.AreEqual(expectedResult, list.Count);
There are more complicated cases involving navigation properties but writing test like this really does not make much sense to me. Again I mean if the mocking framework can mock OK, the test should simply pass. Could you let me know if I'm understanding about testing as well as mocking the wrong way? If the logic is just simple (like the ones I listed at first), do we really need this mock to test it in a non-sense way? It's worth noting that if the test runs the actual implementation and uses Assert
to check the result, then it does make sense to me because at least now the actual code is run and the result is real.
Aucun commentaire:
Enregistrer un commentaire