Merge pull request #9 from f-meloni/dependabot/bundler/cocoapods-downloader-1.6.3
Swift Framework for Spy Objects
To create a spy object you just have to implement the TestSpy protocol on your test class.
class TestClass: TestSpy { enum Method: Equatable { case test case testWithArgument(arument: Int) } var callstack = CallstackContainer<Method>() }
Then when the method you want to test is called you have to record the method in the callstack
extension TestClass: TestProtocol { func test() { callstack.record(.test) } func testWithArgument(argument: Int) { callstack.record(.testWithArgument(argument: argument)) } }
XCTAssertTrue(spyObject.check(method: .test, predicate: CallstackMatcher.any))
expect(spyObject).to(haveReceived(.test))
There are some default matchers that can be used on the test to check that callstack content.
The main matchers are:
XCTAssertTrue(spyObject.check(method: .test, predicate: CallstackMatcher.before(.testWithArgument(argument: 1))))
expect(spyObject).to(haveReceived(.test), .before(.testWithArgument(argument: 1)))
Sourcery offers a good way to automatically generate spy objects. You can find an example stancil file to generate Spy Objects here
to use it:
sourcery --sources "$SOURCESPATH" --templates "$TEMPLATESPATH" --output "$OUTPUTPATH" --args module="$CURRENTFRAMEWORKNAME",import="Foundation",import="UIKit"...
// sourcery: autoSpy
$OUTPUTPATH
Franco Meloni, franco.meloni91@gmail.com
TestSpy is available under the MIT license. See the LICENSE file for more info.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
TestSpy
Swift Framework for Spy Objects
Requirements
Create a spy object
To create a spy object you just have to implement the TestSpy protocol on your test class.
Then when the method you want to test is called you have to record the method in the callstack
Use the spy object in tests
Use the spy object in tests with Nimble
Callstack Matchers
There are some default matchers that can be used on the test to check that callstack content.
The main matchers are:
Usage
Usage with Nimble
Automatically generate Spy Objects with Sourcery
Sourcery offers a good way to automatically generate spy objects. You can find an example stancil file to generate Spy Objects here
to use it:
// sourcery: autoSpy
$OUTPUTPATH
on your test projectAuthor
Franco Meloni, franco.meloni91@gmail.com
License
TestSpy is available under the MIT license. See the LICENSE file for more info.