Closed renanstig closed 7 years ago
Hi, thanks again for reporting. I have not seen such a problem before. Are you using CocoaPods?
I have created a demo app with a unit test. It tests loading of remote images into Auk scroll view.
Xcode: 8.1 (8B62) Cocoapods: 1.2.0.rc.1
The podfile:
platform :ios, '9.0'
use_frameworks!
def shared_pods
pod 'moa', '~> 8.0'
pod 'Auk', '~> 7.0'
end
target 'AukSliderInTheMiddle' do
shared_pods
end
target 'AukSliderInTheMiddleTests' do
shared_pods
end
View controller:
import UIKit
import Auk
class MyViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
loadImages();
}
func loadImages() {
scrollView.auk.show(url: "https://bit.ly/auk_image")
scrollView.auk.show(url: "https://bit.ly/moa_image")
}
}
The unit test
import XCTest
@testable import AukSliderInTheMiddle
import moa
class AukSliderInTheMiddleTests: XCTestCase {
func testExample() {
// Create simulator to catch downloads of the given image
let simulator = MoaSimulator.simulate("auk_image")
// Load view controlle
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "myViewController") as! AukSliderInTheMiddle.MyViewController
// Load view controller
vc.loadView()
// Add remote images to the scroll view
vc.loadImages()
// Check the image download has been requested
XCTAssertEqual(1, simulator.downloaders.count)
XCTAssertEqual("https://bit.ly/auk_image", simulator.downloaders[0].url)
// Simulate server response with an image
let image = UIImage(named: "35px.png", in: Bundle(for: self.classForCoder), compatibleWith: nil)!
simulator.respondWithImage(image)
// Verify the image is loaded into the scroll view
XCTAssertEqual(35, vc.scrollView.auk.images[0].size.width)
}
}
Let me know if it helps.
Hello @evgenyneu ,
Thanks for you quick reply. I'm not using CocoaPods, I downloaded the files and imported them to my project. Could this be the problem?
Best regards, Renan.
@renanstig, thanks for the clarification. I have created another demo app where I have included moa and Auk files directly instead of using CocoaPods. The unit tests still work fine for me.
Please note that I am not adding moa and Auk to the test target. Instead the unit test file has
@testable import NameOfYourAppTarget
Here is the demo project: TestingAuk.zip
Let me know if it fixes your problem.
Hi @evgenyneu ,
Thanks for the replying my last message. Adding this line solved my issue.
Thanks, Renan.
I am glad it helped. Good luck.
Hello,
I'm implementing Unit test in my app, but when I added my ViewController to Tests target, Auk class started giving me the error: "Ambiguous use of auk".
I've already cleaned the derived data and also added both Auk and Moa to Tests target.
I hope you can help me on that, Best regards, Renan.