Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Swift

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Setup Swift
uses: fwal/setup-swift@v2
with:
swift-version: '6.0.0'
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# EasyMock

**Simulate. Test. Verify.**
A lightweight and expressive library for unit testing in Swift — supporting `async/await`, delays, error simulation, and call tracking.
[![Swift](https://github.com/EasyPackages/EasyMock/actions/workflows/swift.yml/badge.svg)](https://github.com/EasyPackages/EasyMock/actions/workflows/swift.yml)

## Simulate. Test. Verify

---
A lightweight and expressive library for unit testing in Swift — supporting `async/await`, delays, error simulation, and call tracking.

## Overview

Expand All @@ -19,8 +20,6 @@ It’s ideal for testing interactions, async flows, and error handling — witho
- ❗ Error simulation (`throw`)
- 🧪 Designed for clarity in unit tests

---

## Why Use EasyMock?

### Replace This:
Expand Down Expand Up @@ -61,8 +60,6 @@ struct AuthenticatorMock: Authenticator {
}
```

---

## Installation

### Using Swift Package Manager
Expand All @@ -87,19 +84,6 @@ In your target:
)
```

---

## Library Structure

| Type | Name | Purpose |
|--------------------|-----------------------|----------------------------------------|
| Mock | `Mock` | Basic sync mock |
| AsyncMock | `AsyncMock` | Mock with `async/await` |
| ThrowableMock | `ThrowableMock` | Mock that can simulate thrown errors |
| AsyncThrowableMock | `AsyncThrowableMock` | Full-featured async mock with error and delay support |

---

## Examples

### Basic Mock
Expand Down Expand Up @@ -144,16 +128,12 @@ let value = try await asyncMock.synchronize("ping")
XCTAssertEqual(value, 42)
```

---

## Supported Platforms

- iOS 13+
- macOS 10.15+
- Swift 5.9+

---

## Author

Created by [Paolo Prodossimo Lopes](https://github.com/PaoloProdossimoLopes)
Expand Down
10 changes: 8 additions & 2 deletions Tests/EasyMockTests/AsyncMockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct AsyncMockTests {
@Test("should wait for the configured delay before completing")
func testsynchronizeAppliesDelay() async {
let delay = 0.2
let tolerance = 0.05
let clock = ContinuousClock()
let start = clock.now
let sut = makeSut()
Expand All @@ -162,8 +163,13 @@ struct AsyncMockTests {
await sut.synchronize("any-input")

let duration = start.duration(to: clock.now)
#expect(duration >= .seconds(delay))
#expect(duration <= .seconds(delay + (delay * 0.1)))
let minimumExpected = delay
let maximumExpected = delay + tolerance

#expect(
duration >= .seconds(minimumExpected) && duration <= .seconds(maximumExpected),
"Duration (\(duration)) was not within the expected range (\(minimumExpected)s to \(maximumExpected)s)"
)
}

@Test("should not trigger observers when mocking delay")
Expand Down
10 changes: 8 additions & 2 deletions Tests/EasyMockTests/AsyncThrowableMockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct AsyncThrowableMockTests {
@Test("should wait for the configured delay before completing")
func testsynchronizeAppliesDelay() async throws {
let delay = 0.2
let tolerance = 0.05
let clock = ContinuousClock()
let start = clock.now
let sut = makeSut()
Expand All @@ -200,8 +201,13 @@ struct AsyncThrowableMockTests {
try await sut.synchronize("any-input")

let duration = start.duration(to: clock.now)
#expect(duration >= .seconds(delay))
#expect(duration <= .seconds(delay + (delay * 0.1)))
let minimumExpected = delay
let maximumExpected = delay + tolerance

#expect(
duration >= .seconds(minimumExpected) && duration <= .seconds(maximumExpected),
"Duration (\(duration)) was not within the expected range (\(minimumExpected)s to \(maximumExpected)s)"
)
}

@Test("should not trigger observers when mocking delay")
Expand Down