Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import UIKit
import PlaygroundSupport
import XCTest
struct Person {
let firstName: String
let lastName: String
let address: String
struct ViewModel {
var person: Person
var nameAndAddress: String {
return "\(person.firstName) \(person.lastName), \(person.address)"
init() {
person = Person(firstName: "John",
lastName: "Appleseed",
address: "1 Infinite Loop, Cupertino, CA")
let label = UILabel()
label.text = ViewModel().nameAndAddress
label.backgroundColor = UIColor.white
PlaygroundPage.current.liveView = label
class PersonTest: XCTestCase {
override func setUp() {
override func tearDown() {
func testResultOfNameAndAddressFunc() {
"John Appleseed, 1 Infinite Loop, Cupertino, CA")
class PlaygroundTestObserver : NSObject, XCTestObservation {
@objc func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
print("Test failed on line \(lineNumber): \(!), \(description)")
let observer = PlaygroundTestObserver()
let center = XCTestObservationCenter.shared()
struct TestRunner {
func runTests(testClass:AnyClass) {
print("Running test suite \(testClass)")
let tests = testClass as! XCTestCase.Type
let testSuite = tests.defaultTestSuite()
let run = testSuite.testRun as! XCTestSuiteRun
print("Ran \(run.executionCount) tests in \(run.testDuration)s with \(run.totalFailureCount) failures")
TestRunner().runTests(testClass: PersonTest.self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.