Swift3 : UnitTest
6538 단어 Swift3.0
Swift3에서 UnitTest를 시작했습니다.
처음이므로 설정에서 간단한 테스트 케이스를 만듭니다.
환경
mcOS siera
xcode:8.2.1
swift3
프로젝트 생성
MyUnitTest의 이름으로 프로젝트를 만듭니다. "include unit tests"를 체크하면 자동으로 추가됩니다.

이미 구현중인 프로젝트의 경우 아래를 클릭하여 Bundle을 추가하면 UnitTest가 추가됩니다.
File>New>Target


iOS Unit Testing Bundle을 선택하여 설치하면 OK
ViewController에 Function을 하나 추가해 보겠습니다.
ViewController.swiftimport UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
/// 入力された文字列が数字かどうか判別
///
/// - Parameter numStr: 文字列
/// - Returns: 判別結果
func isNumber(numStr: String) -> Bool {
if Int(numStr) != nil {
return true
} else {
return false
}
}
}
ViewController에 추가한 Function을 테스트하는 테스트 케이스 생성
테스트 파일 추가


Unit Test Case를 선택합니다. "Ui Test Case"와 아이콘이 같기 때문에 실수하지 마십시오. 빠져요.

테스트 케이스 작성
@testable import MyUnitTest 추가
그런 다음 ViewController를 생성하고 테스트 케이스를 추가하기 만하면됩니다.
이번에는 쉽게 True, False가 올바르게 리턴되어 있는지 확인합니다.
ViewControllerTests.swiftimport XCTest
@testable import MyUnitTest
class ViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
let vc = ViewController()
func test_isNumber関数に数字の文字列が入力された場合Trueがリタンされる() {
XCTAssertTrue(vc.isNumber(numStr: "123"))
}
func test_isNumber関数に数字の文字列が入力された場合Falseがリタンされる() {
XCTAssertFalse(vc.isNumber(numStr: "テスト"))
}
}
테스트 실행
Product>Test 실행

Function 옆의 실행 버튼을 눌러도 실행 가능
Reference
이 문제에 관하여(Swift3 : UnitTest), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/HavenSpring/items/86454f2f3b753a661f0c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
mcOS siera
xcode:8.2.1
swift3
프로젝트 생성
MyUnitTest의 이름으로 프로젝트를 만듭니다. "include unit tests"를 체크하면 자동으로 추가됩니다.

이미 구현중인 프로젝트의 경우 아래를 클릭하여 Bundle을 추가하면 UnitTest가 추가됩니다.
File>New>Target


iOS Unit Testing Bundle을 선택하여 설치하면 OK
ViewController에 Function을 하나 추가해 보겠습니다.
ViewController.swiftimport UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
/// 入力された文字列が数字かどうか判別
///
/// - Parameter numStr: 文字列
/// - Returns: 判別結果
func isNumber(numStr: String) -> Bool {
if Int(numStr) != nil {
return true
} else {
return false
}
}
}
ViewController에 추가한 Function을 테스트하는 테스트 케이스 생성
테스트 파일 추가


Unit Test Case를 선택합니다. "Ui Test Case"와 아이콘이 같기 때문에 실수하지 마십시오. 빠져요.

테스트 케이스 작성
@testable import MyUnitTest 추가
그런 다음 ViewController를 생성하고 테스트 케이스를 추가하기 만하면됩니다.
이번에는 쉽게 True, False가 올바르게 리턴되어 있는지 확인합니다.
ViewControllerTests.swiftimport XCTest
@testable import MyUnitTest
class ViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
let vc = ViewController()
func test_isNumber関数に数字の文字列が入力された場合Trueがリタンされる() {
XCTAssertTrue(vc.isNumber(numStr: "123"))
}
func test_isNumber関数に数字の文字列が入力された場合Falseがリタンされる() {
XCTAssertFalse(vc.isNumber(numStr: "テスト"))
}
}
테스트 실행
Product>Test 실행

Function 옆의 실행 버튼을 눌러도 실행 가능
Reference
이 문제에 관하여(Swift3 : UnitTest), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/HavenSpring/items/86454f2f3b753a661f0c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
/// 入力された文字列が数字かどうか判別
///
/// - Parameter numStr: 文字列
/// - Returns: 判別結果
func isNumber(numStr: String) -> Bool {
if Int(numStr) != nil {
return true
} else {
return false
}
}
}
ViewController에 추가한 Function을 테스트하는 테스트 케이스 생성
테스트 파일 추가


Unit Test Case를 선택합니다. "Ui Test Case"와 아이콘이 같기 때문에 실수하지 마십시오. 빠져요.

테스트 케이스 작성
@testable import MyUnitTest 추가
그런 다음 ViewController를 생성하고 테스트 케이스를 추가하기 만하면됩니다.
이번에는 쉽게 True, False가 올바르게 리턴되어 있는지 확인합니다.
ViewControllerTests.swiftimport XCTest
@testable import MyUnitTest
class ViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
let vc = ViewController()
func test_isNumber関数に数字の文字列が入力された場合Trueがリタンされる() {
XCTAssertTrue(vc.isNumber(numStr: "123"))
}
func test_isNumber関数に数字の文字列が入力された場合Falseがリタンされる() {
XCTAssertFalse(vc.isNumber(numStr: "テスト"))
}
}
테스트 실행
Product>Test 실행

Function 옆의 실행 버튼을 눌러도 실행 가능
Reference
이 문제에 관하여(Swift3 : UnitTest), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/HavenSpring/items/86454f2f3b753a661f0c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import XCTest
@testable import MyUnitTest
class ViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
let vc = ViewController()
func test_isNumber関数に数字の文字列が入力された場合Trueがリタンされる() {
XCTAssertTrue(vc.isNumber(numStr: "123"))
}
func test_isNumber関数に数字の文字列が入力された場合Falseがリタンされる() {
XCTAssertFalse(vc.isNumber(numStr: "テスト"))
}
}
Product>Test 실행

Function 옆의 실행 버튼을 눌러도 실행 가능

Reference
이 문제에 관하여(Swift3 : UnitTest), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/HavenSpring/items/86454f2f3b753a661f0c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)