I've got a stock standard class call GeoRssParserDelegate which needs to be tested.
In my swift unit test I've got this:
func testParser()
{
var bundle = NSBundle(forClass:GeoRssParserTest.classForKeyedArchiver())
var path = bundle.pathForResource("test", ofType: "xml")
let data = NSData.dataWithContentsOfFile(path, options: NSDataReadingOptions.DataReadingMapped, error: nil)
let xmlParser = NSXMLParser(data:data)
let delegate = GeoRssParserDelegate() <-- Compiler fails here
var bStatus = xmlParser.parse()
XCTAssertTrue(bStatus, "Parse failed", file: __FILE__, line: __LINE__)
}
The compiler fails on the line highlighted above. The compiler error is Use of unresolved idenitifier GeorRssParserDelegate
This class does exist and builds with the product itself. Is anything special required?
You have to import your application's module into your unit test. This is usually your app name. For example, if your app name is GeoRssParser
the import
statement would be:
import GeoRssParser
Solution for Xcode 8 and UP which works for me:
@testable import Product_Module_Name
note: not the target name but product's name.
Regarding answers above: making without @testable
will require to make classes and methods public which changes the design of the app architecture. if you don't want to change it better to use this solution so you won't need to make changes to class being public or no.
Many thanks to this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With