Mockity™ is a C++ test helper class for Microsoft Visual Studio that helps us in inspecting classes and creating mocks. The project is discontinued on our end and we have moved to a Catch2-based testing. Mockity™ codes are available on Github.
You can obtain the files from the Mockity™ GitHub repo and place them in the appropriate projects of your solution as described in the Files section below.
The .hpp extension indicates that there is no applicable .cpp file
Mockity™ consist of the following files, to be placed in the indicated sections of your solution:
Part of dev project mockity_project.hpp
#define directives that make development a bit more transparent.
Part of dev project mockity_project.hint
Hints for the Visual Studio IDE
Part of test project mockity_tests.hpp
The main Mockity™ file.
Part of test project mockity_tests.hint
Hints for the Visual Studio IDE
Componens and use
The name of each element starts with the word Mockity so that autosuggest can offer Mockity's various elements easily.
This file contains only two defines. MOCKITY_PROTECTED and MOCKITY_VIRTUAL can be used when the only reason to make something protected or virtual is for the Mockity derived classes to work properly. They simply expand to protected and virtual, respectively.
- (define) MOCKITY_MS_TEST_INCLUDE: Shorthand when icluding CppUnitTest.h
- (define) MOCKITY_USE_MS_TEST_NAMESPACE: Shorthand for using the MS Test namespace
- (define) MOCKITY_SRAND: Shorthand for a fixed "random" seed
- (define) MOCKITY_FAIL_STUB: Stub for unimplemented tests. Fails the test with the message highlighting the need to implement it properly.
- (define) MOCKITY_INIT_STRINGER: Calls Mockity::Stringer's constructor
- (define) MOCKITY_WITH_STRINGER: Provides for public inheritance from Stringer
- (namespace) Mockity: The Mockity™ namespace
- (class) Mockity::Stringer: The Stringer inspection class. See below for more details.
The Mockity::Stringer class
Mockity::Stringer is Mockity's inspector helper class. It should be one of the parent classes of the mock/inspector classes you create. Stringer helps count function calls and track calling order. Currently, Mockity::Stringer is not thread-safe.
- void expectOrder(std::string s): Call it from the test method when defining your expected call order. Pass the code/name of the next expected method call to record the order the methods are expected to be called.
- void countFunctionCall(std::string s): Used in the virtual method before calling the actual method in the parent class. Just pass it the code/name of the current method call in order to count how many times it is called. countFunctionCall could have been defined protected but it is made public for added flexibility.
- bool assertOrder() const: returns true if the actual calling order is in line with the expectations. You can then simply Assert::IsTrue(pMockObject->assertOrder()).
- unsigned getFunctionCallCount(std::string s) const: returns the number of calls to a specific code/method. You can check this output as part of one of your assertions.
Mockity::Stringer is named, in the footsteps of Dr. Watson, after Mr. Stringer, Miss Marple's aide in the Miss Marple films of the 1960s featuring Margaret Rutherford as Miss Marple and her husband, Stringer Davis, as Mr. Stringer.
Issues and known deficiencies
There are plenty of improvement possibilites. Please see our GitHub Issue Tracker to see but a few.
Click here to access the Mockity™ GitHub repo.
Please see our GitHub Issue Tracker.
The license text is the following:
Copyright (c) 2020 FINAL Neural Architecture Laboratories
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software" ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.