Skip to content

Instantly share code, notes, and snippets.

@mkchoi212
Created July 6, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkchoi212/e608c9a7332f9bb9cd0c2ed6b615b6c0 to your computer and use it in GitHub Desktop.
Save mkchoi212/e608c9a7332f9bb9cd0c2ed6b615b6c0 to your computer and use it in GitHub Desktop.
This is the ideal testing code to test VLCMedia::parse
func testLength() {
let tests: [(path: String, expected: VLCTime)] = [
("https://youtube.com/some_video_here", VLCTime(int: 12345)),
]
for (path, expected) in tests {
let media = VLCMedia(url: URL(string: path)!)
let expection = self.expectation(description: "mediaDidFinishParsing called")
let delegate = MockMediaDelegate(parseExpectation: expection)
media.delegate = delegate
// How can this be mocked?
// We should not make any networking calls in the unit test
media.parse(withOptions: VLCMediaParsingOptions(VLCMediaParseNetwork))
// Waiting for 5 seconds here is very fragile as well
// e.g. tests in VLC-iOS sometimes fail here
waitForExpectations(timeout: 5) { err in
XCTAssertNil(err)
XCTAssertEqual(media.length.intValue, expected.intValue)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment