Can the Mock framework do this for me?

I'm a little confused

from the wiki: "That means a true layout ... running tests against the data passed to the method calls as arguments."

I have never used unit testing or falsification. I thought unit tests were for automatic tests, what are test layouts for?

What I want is an object that replaces my database, which I can use later, but don’t know which database or orm tool I use.

When I execute my program using mocks, can I easily replace them with POCO later to make the entity structure, for example, work pretty quickly?

edit: I don't want to use unit testing, but using Mocks as a complete replacement for entities + databases would be nice.

+3
source share
2 answers

Yes, I think you are a little confused.

Layout frames are designed to create "Mock" objects, which basically fake part of the functionality of your real objects, so you can pass them to methods during tests without addressing the problem of creating a real object for testing.

Let's look at a quick example.

Say you have a Save () method that takes a Doc object and returns a boolean success flag

public bool Save(Doc docToSave(){...}

, unit test , , "()". , .

Mocking "Doc" .

, - :

CreateMock of type Doc
SetReturnValue for method Doc.data = "some test data"

Doc, " ", ".data".

:

public void MyTest()
{
    ...
    bool isSuccess = someClass.Save(dummyDoc);
    ...
}

, , "" ()()()() (")() (Access) dummyDoc, , .

, , , Doc, , , , . Mocking , , Doc.

- , . .

-, , , , , , /, , .

+6

, . NHibernate, Entity Framework. Entity Framework.

O/RM ( ).

( , , , /, .)

() / O/RM.

- , . , , . , . , .

+2

Source: https://habr.com/ru/post/1733785/


All Articles