Search code examples
swiftxcodeswift5xctest

How to verify a particular text is present inside a log (String format) in swift?


let command = // some shell command execution that prints some log in terminal

command.description //This gives me the String representation

let textToSearch = "some string value "

//My approaches

let status = command.description.conatains(textToSearch)

XCTAssert(status, "The Text is not present!") // Fail

let status2 = command.description.range(of: textToSearch) != nil

XCTAssert(status, "The Text is not present!") // Fail


Solution

  • let command = Foo()
    let description = command.description
    let textToSearch = "some string value"
    let status = description.localizedLowercase.contains(textToSearch.localizedLowercase)
    
    XCTAssertTrue(status, "The Text is not present!")