2 years ago
#69117
Radhika Chilukuri
Swift unit test for a trailing closure in a function
Function with a Trailing closure:
code(for: "Hello world") {
func hello(_ name: String? = nil) -> String {
return "Hello, \(name ?? "World")!"
}
}
Unit tests for HelloWorld:
public class HelloWorldUnitTests: XCTestCase {
func testHello() {
XCTAssertEqual(hello(), "Hello, World!")
}
static var allTests: [(String, (HelloWorldUnitTests) -> () throws -> Void)] {
return [
("testHello", testHello),
]
If I make hello() as public without closure, tests were passed.I want to make it work with trailing closure within code function. Please help me with this
swift
unit-testing
closures
xctest
0 Answers
Your Answer