TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✓ |
Maintained by kviksilver.
Smock makes testing protocol extensions in Swift easier by providing capability to record selector calls, parameters and stub return values
Look for ProtocolUnderTest
, ProtocolUnderTestMock
and TestingProtocolExtensions
in Tests for more details.
Basic example:
Protocol defines following interface
protocol ProtocolUnderTest: class {
func functionToTest()
func functionToImplement()
}
Extension implements functionToTest
that calls functionToImplement
extension ProtocolUnderTest {
func functionToTest() {
functionToImplement()
}
}
To test that extension actually does required work (on our case function call) we create a mock in test target that conforms to ProtocolUnderTest
and Mock
protocols, implement required functionToImplement
as follows:
class ProtocolUnderTestMock: NSObject, ProtocolUnderTest, Mock {}
extension ProtocolUnderTestMock {
func functionToImplement() {
registerSelector(#selector(functionToImplement))
}
}
Swift Package Manager
To use Swift Package Manager try adding following to your Package.swift file:
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
targets: [],
dependencies: [
.Package(url: "https://github.com/kviksilver/Smock.git", majorVersion: 0),
]
)
kviksilver, [email protected]
Smock is available under the MIT license. See the LICENSE file for more info.