Miles

2.3.3

A thin wrapper around XCTest Macros to make tests just a bit more readable.
MadeByHecho/Miles

What's New

Version 2.3.3

2021-10-12T19:06:53Z

Updates so all helpers properly use the #file and #line parameters.

Miles

A thin wrapper around XCTest Macros to make tests just a bit more readable.

Carthage compatible

Miles is a simple solution to an XCTest readability problem.

It feels like every 6 months or so I hop on the Quick/Kiwi bandwagon (because of my frustration with the readability of XCTest) only to grow frustrated with some of the limitations that Xcode imposes. Miles is the simplest solution to the problem that I could come up with.

Miles is named after Darius Miles, a former professional basketball player who also had a role in the 2004 Movie 'The Perfect Score', where he and 5 students try to steal the SAT.

Background

Apple's Xcode includes the XCTest framework, which provides assertion macros to test whether code behaves properly. For example, to assert that 1 + 1 = 2, XCTest has you write:

XCTAssertEqual(1 + 1, 2, "expected one plus one to equal two")

In a more robust matcher framework like Nimble you get the much more readable:

expect(1 + 1).to(equal(2))

In Miles you get something that I think is even more readable:

(1+1).shouldEqual(2)

Usage

Miles.swift defines all the extensions, so make sure it's either included in your Test Target or that you import Miles in the class you're trying to test. Then when you want to validate that the 5+5 = 10 you can do this:

func testThatFivePlusFiveEqualsTen() {
	10.shouldEqual(5 + 5)
}

If you wanted to do something a bit more complicated like validate that a certain string has a suffix, that would look like this:

func testThatMilesEndsInLes() {
	let miles = "miles"
	miles.shouldHaveSuffix("les")
}

Miles currently provides extensions for many of the swift standard types including:

  • String
  • Character
  • Int
  • Float
  • Double
  • Bool
  • NSObject

Because Swift doesn't currently support public extensions on generic types, Miles provides Global functions to validate Array, Dictionary and Optional types.

Installation

The following instructions were taken and repurposed from Quick because it is the best resource I've seen for integrating with a Test Target. As such please note that instead of dragging in Quick and Nimble you'll be dragging in Miles.

How to Install Miles using Carthage

As Test targets do not have the "Embedded Binaries" section, the frameworks must be added to the target's "Link Binary With Libraries" as well as a "Copy Files" build phase to copy them to the target's Frameworks destination.

As Carthage builds dynamic frameworks, you will need a valid code signing identity set up.

  1. Add Miles to your Cartfile.private

    github "MadeByHecho/Miles"
    
  2. Run carthage update

  3. From your Carthage/Build/[platform]/ directory, add Miles to your test target's Link Binary With Libraries build phase

  4. For your test target, create a new build phase of type Copy Files

  5. Set the Destination to Frameworks, then add the Miles framework

This is not 'the one and only way' to use Carthage to manage dependencies, for further reference check out the Carthage documentation

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Mar 14 2024 16:19:44 GMT-0900 (Hawaii-Aleutian Daylight Time)