5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Xcode PlaygroundでUnit Testを走らせる

Posted at

概要

iOS開発でUnit Testを書くとき、これはこう書けるかな?と試したいときがあります。
その時は以下のように書くと保存→実行を即時に行えます。

import UIKit
import XCTest

class ViewController {
}

class ViewControllerTests: XCTestCase {
    func testInitialize() {
        let vc = ViewController()
        XCTAssertNotNil(vc)
    }
}

ViewControllerTests.defaultTestSuite.run()

XCTestをimportして、テストを実行したいタイミングでViewControllerTests.defaultTestSuite.run()を呼んであげればOKです。

Xcode PlaygroundのConsoleにテスト実行結果が表示されます。

image.png

実行環境

  • Xcode 9.0
  • Swift 4.0
5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?