Mock Authentication on dao

0
_usuario = CriaUsuario(new Login("Roberto"), new Senha("Senha"));

        var dao = new Mock<IUsuarioDao>();
        dao.Setup(d => d.Autenticar(It.IsAny<Login>(), It.IsAny<Senha>())).Returns(_usuario);


        var usuario = dao.Object.Autenticar(new Login("Roberto"), new Senha("Senha"));

What do I want to know and is it worth doing this type of test? Because I look like this, I'd rather do the test by accessing the database because then I would test the query

Anyway .. what's the best way?

    
asked by anonymous 29.01.2017 / 03:52

1 answer

0

These are different types of tests.

The first one, using mocks , is a unit test. Its purpose is to test the logic / rule that the method implements.

The second is an integration test. The purpose is to test the integration of this part of the system with another system, in this case the database.

If it's worth doing the tests, I do not know, only you can qualify their importance and quantify the cost / benefit of doing them.

If you must do the first, second, or both, you should choose the right test level for the situation in question. A business class should be tested in isolation, as DAO (perhaps) needs to be tested along with the database.

    
29.01.2017 / 12:34