2
2

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.

Swift覚え書き Test

Posted at

自分用の覚え書き。
たぶんこのままだとコンパイルエラーになります。

Swiftの例外はObCの例外機構と異なるため、SwiftにはExpression関連のアサート関数が存在しない。

import XCTest

@testable import test

class testTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        
        let expression = false
        let expression2 = true
        let msg = "msg"
        let nilObj:String?
        let accuracy:Float = 1.0
        let num01 = 1
        let num02 = 2
        
        XCTAssert(expression,  msg)
        
        XCTAssertTrue(expression, msg)
        
        XCTAssertFalse(expression, msg)
        
        XCTAssertNil(nilObj, msg)
        
        XCTAssertNotNil(nilObj, msg)
        
        XCTAssertEqual(expression, expression2, msg)
        
        XCTAssertNotEqual(expression, expression2, msg)
        
        XCTAssertEqualWithAccuracy(expression, expression2, accuracy, msg)
        
        XCTAssertNotEqualWithAccuracy(expression, expression2, accuracy, msg)
        
        // num01がnum02より同じか小さいことを期待する
        XCTAssertLessThanOrEqual(num01, num02, msg)
        
        // num02がnum02より小さいことを期待する
        XCTAssertLessThan(num01, num02, msg)
        
        // num01がnum02より同じか大きいことを期待する
        XCTAssertGreaterThanOrEqual(num01, num02, msg)
        
        // num02がnum02より大きいことを期待する
        XCTAssertGreaterThan(num01, num02, msg)
        
        // 必ず失敗する
        XCTFail(msg)
    }
    
    func testPerformanceExample() {
        // This is an example of a performance test case.
        self.measureBlock {
            // Put the code you want to measure the time of here.
        }
    }
    
}
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?