cellに文字が表示されているかどうかのtestを書きたいのですが、以下のエラーでテストが失敗します。解決法を教えていただけますと幸いです。
[HogeTests.AnswerListTests 表示__一行目にLabelが表示されている] : failed: caught "NSInternalInconsistencyException", "unable to dequeue a cell with identifier answerListCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard"
storyBoard上では、cellのidentiferに answerListCell
を指定しているので、実際の画面では文字が表示されているのですが、テストだと失敗します。
- viewController
import UIKit class AnswerListViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "answerListCell", for: indexPath as IndexPath) as! AnswerListCell cell.hogeLabel.text = "hoge" return cell } } class AnswerListCell: UITableViewCell{ @IBOutlet weak var hogeLabel: UILabel! }
- test
class AnswerListTests: QuickSpec{ override func setUp() { continueAfterFailure = false } override func spec(){ var subject = AnswerListViewController() beforeEach { subject.beginAppearanceTransition(true, animated: false) subject.endAppearanceTransition() } describe("表示"){ it("一行目にLabelが表示されている"){ let indexPath = IndexPath(row: 0, section: 0) subject.tableView.cellForRow(at: indexPath) # この行でエラー発生 expect(cell.hogeLabel!.text).to(equal("hoge")) } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/20 01:16 編集