How to mock for same input and different return values in a for loop in golang

I had a similar problem. The solution was the method Once() In your mock add an .Once() and repeat the mock with each result you need. Something like this: lib.Mock.On(“method”, arg).Return(test.mockError).Once() lib.Mock.On(“method”, arg).Return(nil).Once() Each mock result will be returned only once. https://godoc.org/github.com/stretchr/testify/mock#Call.Once

Where do you put your unit test?

I favour keeping unit-tests in separate source files in the same directory as production code (#3). Unit tests are not second-class citizens, their code must maintained and refactored just like production code. If you keep your unit tests in a separate directory, the next developer to change your production code may miss that there are … Read more

Run/Debug Test in Current Context with Visual Studio 2012

It turns out that one can right-click on the source code of any of: A specific test (public void MyTest()) A class containing tests (public class MyTestClass) A namespace containing tests (namespace My.Project.Test) and get a context menu to either run or debug tests within each given scope. (Note: Text in Context Menu does not … Read more

What does enable_testing() do in cmake?

When you call add_test(…), CMake will not generate the tests unless enable_testing() has been called. Note that you usually don’t need to call this directly. Just include(CTest) and it will invoke it for you. My CMake setup often looks like this: include(CTest) # note: this adds a BUILD_TESTING which defaults to ON # … if(BUILD_TESTING) … Read more