logo
down
shadow

Should I keep using mocks and stubs in domain testing?


Should I keep using mocks and stubs in domain testing?

By : Fabrice Hauhouot
Date : November 22 2020, 10:54 AM
To fix the issue you can do From unit testing point of view you should be using mocks and stubs. On of the traits of good unit tests is isolation, which means they shouldn't rely on external components (like data access).
However, you might want to (or need to) have another type of tests1 - integration tests - which allow you to test components together (in your case you would test integration between domain and data access). In those tests you use actual implementations rather than mocks/stubs.
code :


Share : facebook icon twitter icon
Effective testing in C++ with stubs and mocks? (possible?)

Effective testing in C++ with stubs and mocks? (possible?)


By : user2322698
Date : March 29 2020, 07:55 AM
it helps some times So, I found my solution, after stumbling upon a remarkably well endowed list at wikipedia of C++ testing frameworks, I stumbled upon GoogleTest and the Google C++ Mocking Framework. Which fulfills all my requirements, whilst it's a little trickier to use than the Ruby counterparts, it is equally well featured.
One thing I'm not so happy, or certain about is stubbing system calls - it looks as though I would have to wrap them in my own class which I can then mock responses on - I don't have a strong feeling either way about this, but it doesn't feel optimal, although does allow me to be clear about what pieces of system functionality are relied upon.
C++ Unit Testing: Stubs (not mocks)?

C++ Unit Testing: Stubs (not mocks)?


By : user3186942
Date : March 29 2020, 07:55 AM
To fix this issue I think the missing piece of the puzzle is that you don't have to set an expectation on a method and instead you can just set a default return value.
Mocks
code :
EXPECT_CALL(turtle, PenDown())
      .Times(AtLeast(1));
ON_CALL(foo, Sign(_))
      .WillByDefault(Return(-1));
EXPECT_CALL(foo, Bar(_))
    .WillRepeatedly(...);
What's the better practice for testing code which relies on a DB? Mocks and stubs? Or seeded data?

What's the better practice for testing code which relies on a DB? Mocks and stubs? Or seeded data?


By : Vishal Ruparel
Date : March 29 2020, 07:55 AM
seems to work fine There are a lot of ways to test code that interacts with a database.
The repository pattern is one method of creating a facade over the data access code. It makes it easy to stub/mock out the repository during test. This is useful when a piece of business logic needs tested in isolation and dummy values can help test different branches of the code.
Unit testing with stubs and mocks

Unit testing with stubs and mocks


By : Lénaïc MIGNOT
Date : March 29 2020, 07:55 AM
This might help you Yes, you are correct that there is something wrong with how the test is written. In fact, you are not testing MyClass. You are instead testing that the mocking framework you use works. As proof, comment the two lines that use MyClass and run the test again. It will still pass:
code :
[TestMethod]
public void TestMethod()
{
    var groupId = "ABC";
    var personId = 1;

    ver personInfo = new PersonInfo()
    {
      Id = personId,
      FirstName = "Sam",
      LastName = "Smith"  `
    }

    var groupStub = new Mock<IGroupRepository>;
    groupStub.Setup(x=> x.GetById(groupId)).Returns(new Group(){
            Id = groupId,
            Persons = List<Person>()
            {
                new Person()
                {
                    Id = personId,
                    FirstName = "George",
                    LastName = "Bolton",
                }
            }
        }
    });

    // var myClass = new MyClass();
    // myClass.Execute(personInfo, groupId);

    var group = groupStub.GetById(groupId);
    var person = group.Persons.First(p=> p.Id == personId);

    Assert.AreEqual(personInfo.FirstName, person.FirstName);
}
groupStub.Received().Save(
    Arg.Is<Group>(group =>
    {
        return groupId.Id == groupId && 
            group.Persons[0].Id == personId &&
            group.Persons[0].FirstName == "Sam" &&
            group.Persons[0].LastName == "Smith";
    });
When to use stubs/mocks and when to use real objects in unit testing?

When to use stubs/mocks and when to use real objects in unit testing?


By : Jyoti Kumari
Date : March 29 2020, 07:55 AM
To fix this issue The why of mocking is to be able to write unit test that means a test which is: fast, isolated, repeatable, self validating and Thorough and Timely (F.I.R.S.T)
To be able to test a unit/module in isolation you may need to mock/stub any external module (database access, api call, logging system...).
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org