From 8f7c286755c7f24888e51a58ef89c821db1d70dd Mon Sep 17 00:00:00 2001 From: Paolo Prodossimo Lopes <70642432+PaoloProdossimoLopes@users.noreply.github.com> Date: Tue, 13 May 2025 07:01:02 -0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=91=B7=20configure=20the=20pipeline?= =?UTF-8?q?=20to=20build=20and=20test=20for=20spm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/swift.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/swift.yml diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..4ef8c8c --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,22 @@ +# This workflow will build a Swift project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift + +name: Swift + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v From 88aa0c1fbacafcc4d79b9e2ba84c39c7e6096610 Mon Sep 17 00:00:00 2001 From: Paolo Prodossimo Lopes <70642432+PaoloProdossimoLopes@users.noreply.github.com> Date: Tue, 13 May 2025 07:04:30 -0300 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=92=9A=20specify=20version=20of=20swi?= =?UTF-8?q?ft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/swift.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 4ef8c8c..7219c22 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -1,6 +1,3 @@ -# This workflow will build a Swift project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift - name: Swift on: @@ -11,11 +8,14 @@ on: 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 From f7eea85293c7b48f5c3d2a5cddc2592644b640cf Mon Sep 17 00:00:00 2001 From: Paolo Prodossimo Lopes Date: Tue, 13 May 2025 07:22:53 -0300 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20improve=20async=20test=20to=20e?= =?UTF-8?q?nsure=20is=20more=20reliable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tests/EasyMockTests/AsyncMockTests.swift | 10 ++++++++-- Tests/EasyMockTests/AsyncThrowableMockTests.swift | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Tests/EasyMockTests/AsyncMockTests.swift b/Tests/EasyMockTests/AsyncMockTests.swift index 15cb33a..be6c133 100644 --- a/Tests/EasyMockTests/AsyncMockTests.swift +++ b/Tests/EasyMockTests/AsyncMockTests.swift @@ -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() @@ -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") diff --git a/Tests/EasyMockTests/AsyncThrowableMockTests.swift b/Tests/EasyMockTests/AsyncThrowableMockTests.swift index 2d4778a..1100935 100644 --- a/Tests/EasyMockTests/AsyncThrowableMockTests.swift +++ b/Tests/EasyMockTests/AsyncThrowableMockTests.swift @@ -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() @@ -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") From c21275ba796898fbcca4b12707479dfedccb7596 Mon Sep 17 00:00:00 2001 From: Paolo Prodossimo Lopes Date: Tue, 13 May 2025 07:29:16 -0300 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9D=20add=20pipeline=20status=20ba?= =?UTF-8?q?dge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2b9dce5..9d0b5d3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -61,8 +60,6 @@ struct AuthenticatorMock: Authenticator { } ``` ---- - ## Installation ### Using Swift Package Manager @@ -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 @@ -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)