Skip to content

Commit

Permalink
Swift package manager support
Browse files Browse the repository at this point in the history
KIF is on openium fork's master branch, waiting PR merge
  • Loading branch information
kenji21 committed Apr 23, 2020
1 parent c2a10e0 commit 86c3fdb
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 158 deletions.
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
[submodule "Carthage/Checkouts/KIF"]
path = Carthage/Checkouts/KIF
url = https://github.com/kif-framework/KIF.git
[submodule "Carthage/Checkouts/OHHTTPStubs"]
path = Carthage/Checkouts/OHHTTPStubs
url = https://github.com/AliSoftware/OHHTTPStubs.git
[submodule "Carthage/Checkouts/SimulatorStatusMagic"]
path = Carthage/Checkouts/SimulatorStatusMagic
url = https://github.com/shinydevelopment/SimulatorStatusMagic.git
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/openium/SwiftiumTestingKit/compare/v0.6.0...HEAD)
### Added
Swift Package Manager support

### Changed
### Changed

### Removed
Carthage support
SimulatorStatusBarMagic

## [0.6.2](https://github.com/openium/SwiftiumTestingKit/compare/v0.6.2...v0.6.1)
### Added
Expand Down
3 changes: 0 additions & 3 deletions Cartfile

This file was deleted.

3 changes: 0 additions & 3 deletions Cartfile.resolved

This file was deleted.

1 change: 0 additions & 1 deletion Carthage/Checkouts/KIF
Submodule KIF deleted from 0ea470
1 change: 0 additions & 1 deletion Carthage/Checkouts/OHHTTPStubs
Submodule OHHTTPStubs deleted from 543182
1 change: 0 additions & 1 deletion Carthage/Checkouts/SimulatorStatusMagic
Submodule SimulatorStatusMagic deleted from 82529f
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "KIF",
"repositoryURL": "https://github.com/openium/KIF",
"state": {
"branch": "master",
"revision": "f37d791f40f6f112b288eba967e1c1386fbe598b",
"version": null
}
},
{
"package": "OHHTTPStubs",
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs",
"state": {
"branch": null,
"revision": "e92b5a5746ef16add2a1424f1fc19529d9a75cde",
"version": "9.0.0"
}
}
]
},
"version": 1
}
36 changes: 36 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
// https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md

import PackageDescription

let package = Package(
name: "SwiftiumTestingKit",
platforms: [
.iOS(.v10)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftiumTestingKit",
targets: ["SwiftiumTestingKit"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/AliSoftware/OHHTTPStubs", from: "9.0.0"),
.package(url: "https://github.com/openium/KIF", .branch("master")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SwiftiumTestingKit",
dependencies: [
.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs"),
"KIF",
]),
.testTarget(
name: "SwiftiumTestingKitTests",
dependencies: ["SwiftiumTestingKit"]),
]
)
34 changes: 7 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# SwiftiumKit

[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
# SwiftiumTestingKit

This "Kit" adds many feature to speed up iOS app testing. It allows to write Unit tests for testing view controllers "quicker than UI Tests".

Expand All @@ -26,34 +24,16 @@ see more in [STKSoloTests.swift](https://github.com/openium/SwiftiumTestingKit/b

## Installation

### Carthage

[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with [Homebrew](https://brew.sh/) using the following command:

```bash
$ brew update
$ brew install carthage
```
### Swift Package Manager

To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "openium/SwiftiumTestingKit" ~> latest
```

Run `carthage update` to build the framework and drag the built `SwiftiumTestingKit.framework` into your Xcode project.
See [official documentation](https://github.com/apple/swift-package-manager/tree/master/Documentation)

### Setup

Add the following frameworks to your test target and add a `Copy Files` with `frameworks` destimations to your test target build phases:
- `SimulatorStatusMagiciOS.framework`
- `OHHTTPStubs.framework`
- `SwiftiumTestingKit.framework`
- `KIF.framework`

![](doc/copy-frameworks.png)
Add the following libraries to your test target :
- `OHHTTPStubs`
- `SwiftiumTestingKit`
- `KIF`

# To be done :

Expand Down
12 changes: 6 additions & 6 deletions STKTestApp/ViewController.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -23,14 +23,14 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Top label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ldY-JD-zXY">
<rect key="frame" x="153" y="0.0" width="69" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Top label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ldY-JD-zXY">
<rect key="frame" x="153" y="0.0" width="69" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HSL-Bx-caw">
<rect key="frame" x="145.5" y="63" width="84" height="30"/>
<rect key="frame" x="145.5" y="62.5" width="84" height="30"/>
<state key="normal" title="Hello button"/>
<connections>
<action selector="tapped:" destination="-1" eventType="touchUpInside" id="6dL-KA-4kw"/>
Expand Down Expand Up @@ -59,7 +59,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</activityIndicatorView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Wym-q8-nlS">
<rect key="frame" x="0.0" y="288" width="375" height="184"/>
<rect key="frame" x="0.0" y="287.5" width="375" height="184"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="184" id="TzL-h2-rF3"/>
Expand Down
2 changes: 1 addition & 1 deletion STKTestAppTests/STKPilotableHTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class STKPilotableHTTPServerTests: XCTestCase {

// Expect
XCTAssertFalse(allServedAfterQueuing)
XCTAssertEqual(OHHTTPStubs.allStubs().count, 0)
XCTAssertEqual(HTTPStubs.allStubs().count, 0)
}

func testMakeRequestReturnData_emptyData_204() {
Expand Down
2 changes: 2 additions & 0 deletions STKTestAppTests/STKSoloTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class STKSoloTests: XCTestCase {
// Expect
XCTAssertTrue(foundTestTexts[texts[0]] ?? false)
XCTAssertTrue(foundTestTexts[texts[1]] ?? false)
XCTAssertTrue(foundTestTexts[texts[2]] ?? false)
XCTAssertTrue(foundTestTexts[texts[3]] ?? false)
}

func testWaitForText_shouldFindLabelTestUsingPrefix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
// Copyright © 2018 Openium. All rights reserved.
//

import UIKit
import Foundation
import OHHTTPStubs
import OHHTTPStubsSwift
import MobileCoreServices

public func isMethod(_ verb: STKPilotableHTTPServer.HTTPVerb) -> OHHTTPStubsTestBlock {
public func isMethod(_ verb: STKPilotableHTTPServer.HTTPVerb) -> HTTPStubsTestBlock {
return { $0.httpMethod == verb.rawValue }
}

Expand All @@ -31,27 +32,27 @@ public class STKPilotableHTTPServer: NSObject {
}
static func removeFromAllPilotableServers(_ pilotableServer: STKPilotableHTTPServer) {
allPilotableServers.removeAll { $0.server == nil }
pilotableServer.foreverQueuedDescriptors.forEach { OHHTTPStubs.removeStub($0) }
pilotableServer.nonForeverQueuedDescriptors.forEach { OHHTTPStubs.removeStub($0) }
pilotableServer.foreverQueuedDescriptors.forEach { HTTPStubs.removeStub($0) }
pilotableServer.nonForeverQueuedDescriptors.forEach { HTTPStubs.removeStub($0) }
}
static func activateStubMissingAndActivationObservers() {
OHHTTPStubs.onStubMissing({ (request) in
HTTPStubs.onStubMissing({ (request) in
NSLog("no served response queued for request \(request)")
})
OHHTTPStubs.onStubActivation({ (request, descriptor, response) in
HTTPStubs.onStubActivation({ (request, descriptor, response) in
allPilotableServers.forEach({ (unownedServer) in
guard let server = unownedServer.server else { return }
if server.removeDescriptorFromNonForeverQueue(descriptor) {
OHHTTPStubs.removeStub(descriptor)
HTTPStubs.removeStub(descriptor)
}
})
})
}

var foreverQueuedDescriptors = [OHHTTPStubsDescriptor]()
var nonForeverQueuedDescriptors = [OHHTTPStubsDescriptor]()
var foreverQueuedDescriptors = [HTTPStubsDescriptor]()
var nonForeverQueuedDescriptors = [HTTPStubsDescriptor]()

func queue(descriptor: OHHTTPStubsDescriptor, serveForever: Bool) {
func queue(descriptor: HTTPStubsDescriptor, serveForever: Bool) {
if serveForever == false {
descriptor.name = descriptor.debugDescription
nonForeverQueuedDescriptors.append(descriptor)
Expand All @@ -60,7 +61,7 @@ public class STKPilotableHTTPServer: NSObject {
}
}

func removeDescriptorFromNonForeverQueue(_ descriptor: OHHTTPStubsDescriptor) -> Bool {
func removeDescriptorFromNonForeverQueue(_ descriptor: HTTPStubsDescriptor) -> Bool {
var removed = false
let index = nonForeverQueuedDescriptors.firstIndex(where: { (nonForeverDescriptor) -> Bool in
return nonForeverDescriptor.name == descriptor.name
Expand Down Expand Up @@ -166,7 +167,7 @@ public class STKPilotableHTTPServer: NSObject {
return right
}
}
return OHHTTPStubsResponse(data: data ?? Data(), statusCode: statusCode, headers: headers)
return HTTPStubsResponse(data: data ?? Data(), statusCode: statusCode, headers: headers)
}
queue(descriptor: descriptor, serveForever: serveForever)
return urlForRequest(onPath: path)
Expand All @@ -193,7 +194,7 @@ public class STKPilotableHTTPServer: NSObject {
}

let descriptor = stub(condition: isScheme(scheme) && isHost(host) && isPath(path) && isMethod(httpVerb)) { _ in
return OHHTTPStubsResponse(fileAtPath: stubPath,
return HTTPStubsResponse(fileAtPath: stubPath,
statusCode: statusCode,
headers: headers)
}
Expand All @@ -207,7 +208,7 @@ public class STKPilotableHTTPServer: NSObject {
statusCode: Int32 = 301,
serveForever: Bool = false) -> URL {
let descriptor = stub(condition: isScheme(scheme) && isHost(host) && isPath(path)) { _ in
return OHHTTPStubsResponse(data: Data(),
return HTTPStubsResponse(data: Data(),
statusCode: statusCode,
headers: [HTTPHeaders.location.rawValue: toLocation])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit
import XCTest
import KIF
import SimulatorStatusMagiciOS

public class STKSolo: NSObject {
public var animationSpeed: Float = 1.0
Expand Down Expand Up @@ -45,10 +44,6 @@ public class STKSolo: NSObject {
}
testActor.executionBlockTimeout = timeoutForWaitForMethods

SDStatusBarManager.sharedInstance()?.carrierName = STKSolo.defaultCarrierName
SDStatusBarManager.sharedInstance()?.bluetoothState = SDStatusBarManagerBluetoothState.visibleConnected
SDStatusBarManager.sharedInstance()?.enableOverrides()

return testActor
}()
var lastExceptions = [Any]()
Expand Down Expand Up @@ -288,7 +283,9 @@ func isMultipleTestsRun() -> Bool {

extension STKSolo: KIFTestActorDelegate {
public func fail(with exception: NSException!, stopTest stop: Bool) {
lastExceptions.append(exception)
if let exception = exception {
lastExceptions.append(exception)
}
}

public func fail(withExceptions exceptions: [Any]!, stopTest stop: Bool) {
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions Sources/SwiftiumTestingKit/SwiftiumTestingKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct SwiftiumTestingKit {
var text = "Hello, World!"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ extension XCTestCase {

public func dataFromCurrentClassBundleRessource(filename: String, mainBundle: Bool = false) -> Data {
let path = pathFromCurrentClassBundleRessource(filename: filename, mainBundle: mainBundle)
var data: Data? = nil
do {
data = try Data(contentsOf: URL(fileURLWithPath: path))
let data = try Data(contentsOf: URL(fileURLWithPath: path))
return data
} catch let error as NSError {
fatalError("Can't load data from bundle resource \(filename) (path \(path) \(error.localizedDescription))")
}
return data!
}

public func jsonObjectFromRessource(filename: String, mainBundle: Bool = false) -> Any {
let data = dataFromCurrentClassBundleRessource(filename: filename, mainBundle: mainBundle)
var json: Any! = nil
do {
json = try JSONSerialization.jsonObject(with: data)
let json = try JSONSerialization.jsonObject(with: data)
return json
} catch let error as NSError {
fatalError("Can't load json from data of bundle resource \(filename): \(error.localizedDescription)")
}
return json
}

// MARK: -
Expand Down
Loading

0 comments on commit 86c3fdb

Please sign in to comment.