Available Now: Test-Driven Development in Swift with SwiftUI and Combine

mokacoding

unit and acceptance testing, automation, productivity
Archive Tags About Subscribe

Posts tagged "testing"

Tests Are The Best Kind Of Documentation

Fri Jun 03 2022 -testing

Unit tests are a vital tool for writing quality code. They also happen to be the best kind of documentation for your software, the kind that never gets out of date.

How to convince your team to adopt TDD

Thu Mar 24 2022 -testing -tdd -processes

Test-Driven Development is an excellent way of writing code but many people push back against it. To convince your team to adopt it, lead by example. Don't preach. Let the quality of the code your wrote with TDD talk for itself and only suggest TDD when people ask about it.

XCTNSPredicateExpectation is slow, and what to do about it

Fri Feb 25 2022 -Nimble -XCTest -Swift -Testing

Each XCTNSPredicateExpectation requires a timeout of at least 1.1 seconds. That's will unnecessarily slow down your test suite. You can use Nimble's toEventually instead and make your tests as fast as possible.

When to test a @Published property using sink

Sun Oct 17 2021 -Testing -Swift -Combine -XCTest

Swift @Published properties come with an associated Combine Publisher that emits values over time. This free XCTest tutorial explains when to write a unit test that accesses the property directly and when it's instead necessary to subscribe to it using the sink operator.

A real-world example of TDD catching bugs

Wed Aug 25 2021 -swift -testing -tdd -xcode -refactoring

I published a YouTube video with a tutorial on implementing the FizzBuzz algorithm using Test-Driven Development. While recording, I made a couple of thinking or coding mistakes, and, sure enough, the tests immediately pointed them out.

How to write unit tests for SwiftUI apps

Thu Aug 12 2021 -swift -swiftui -testing -tdd

To test SwiftUI applications, don't test SwiftUI code. The SwiftUI framework doesn't lend itself to writing unit tests so don't try to shoehorn views in your test harness. Instead, split layout declaration form content generation logic.

WWDC21: What's New in Testing

Thu Jun 17 2021 -Testing -XCTest -Swift -Talks

A roundup of the testing-related new features announced at WWDC 2021. Including Xcode Cloud, how to test code using async/await, the new XCTExpectFailure and addTearDownBlock APIs, and the new Test Repetition configuration in Test Plans.

How to test Swift async/await code with XCTest

Mon Jun 07 2021 -Xcode -XCTest -Testing -Swift

Swift 5.5 and Xcode 13 introduce the async/await pattern for concurrent code. This tutorial post shows how to write unit tests for asynchronous code in Swift using the XCTest framework.

How to write better tests for Swift date comparisons

Fri Jun 04 2021 -Testing -Swift -XCTest

Testing Swift date comparison code with XCTest can result in indeterministic tests because of the passage of time. To make tests robust and deterministic, decouple them from the system clock by injecting the reference date.

How to manage complex inputs in your Swift tests with Scenario Builders

Thu Apr 29 2021 -Testing -Swift

When writing unit tests in Swift for complex objects, you may need to write a lot of setup boilerplate code in the arrange phase. Scenario Builders are a pattern that extracts and encapsulated all that logic in a single component with an English-like API. This tutorial shows how to build a Scenario Builder in Swift and looks at its pros and cons.

Unit Testing Combine Publisher Cheatsheet

Thu Feb 11 2021 -Testing -Combine -Xcode -XCTest

Snippets to test the behavior of Combine Publishers in XCTest ready to copy and paste into Xcode

How to improve your Test-Driven Development workflow by asking "Do I need this yet?"

Thu Dec 17 2020 -Testing -TDD

The "You Don't Need It Yet" technique to ship software on a schedule results in fast real-world feeback. The same mindset can be applied with Test-Driven Development to move between the Red, Green, and Refactor stages faster.

Write better Swift unit tests with custom XCTest assertions

Thu Dec 10 2020 -XCTest -Xcode -Swift -Testing

The XCTest Swift testing framework has a limited offer of assertions. There's only so much you can do with XCTAssertTrue and XCTAssertEqual. This XCTest tutorial shows how to create custom assertions to make your unit tests and UI tests shorter and clearer.

How to write unit test assertions for Swift Result values

Wed Dec 02 2020 -Swift -Testing -XCTest

Result is one of the most useful types in the Swift language. Learn how to write better unit tests using Result in this XCTest tutorial.

When experiments go wrong

Wed Nov 25 2020 -Books -Testing -Learning

Scientist can learn a lot from failed experiments. To do so, they must be methodical and collect all sorts of information. Softwar developers can learn a lot from failures, too. What are the practicies that can make learning easier?

How to bypass the SwiftUI App when running unit tests

Thu Nov 12 2020 -Swift -SwiftUI -Xcode -Testing

How to make the unit tests of your SwiftUI app safer and faster by preventing them from running the program startup flow. This will avoid all of the launch operations like network requests or reads from the local storage that would affect the global state.

How to decouple unit tests from values that change frequently

Tue Sep 01 2020 -Swift -XCTest -Testing

When the output value of a function changes often but the logic to pick it doesn't, adding a separation layer will make unit tests easier to maintain.

How to run a single test in Xcode

Tue Apr 23 2019 -Xcode -Testing -Productivity

A collection of ways to run a single test or a subset of tests using Xcode.

How to test view controllers navigation

Tue Apr 16 2019 -Swift -Testing -iOS -Software-Design

The answer to "How can I test that a view controller presents another view controller when something happens?" is as simple as defining a delegate.

Better tests for delegates

Tue Mar 12 2019 -Swift -Testing

When testing delegates, we are asserting rigid implementation details. Here's a way to make those tests more flexible.

Code Coverage Is A Broken Metric

Tue Feb 19 2019 -Testing -Refactoring

But you should track it anyways.

Test doubles in Swift: dummies, fakes, stubs, and spies.

Tue Nov 27 2018 -Testing -Swift

An overview of the different kind of doubles we can use in our tests, and how to write them in Swift.

How to split decision and action logic with the Swift type system

Tue Nov 13 2018 -Swift -Testing -Refactoring

There is a subtle way to overload software components, by making them both take decision and act on them. We can simplify these bloated components by separating the responsibility of taking decisions from the one action on them. This will result in leaner and easier to maintain software, and is made simple by the Swift type system.

How to remove duplication from Swift tests with helper functions

Tue Nov 06 2018 -Testing -Xcode -Swift -XCTest

Some code ends up requiring a lot of duplication to be tested. You can remove it by using helper functions encapsulating the shared assertion logic.

Streamlining tests setup with fixtures in Swift

Tue Oct 09 2018 -Testing -Swift

Keeping tests short and focused is important for the health of the test suite. A fixture method to generate instances with default values in the tests helps keeping the setup code short, focused, and readable

Action focused protocols enhance testability

Tue Sep 11 2018 -Testing -Swift

Using protocols describing a single capability or action that can be performed is a way to enhance local reasoning and facilitate testability

If you're not writing tests first you're missing out

Fri Aug 17 2018 -Testing -TDD

A look at the benefits of writing unit tests before production code, in other words TDD.

Quick beforeSuite and afterSuite behaviour

Thu May 11 2017 -Quick -Espresso -Testing

A look at how beforeSuite and afterSuite behave in the Quick testing framework, and the dangers of using them

Quick beforeEach and afterEach behaviour

Mon May 08 2017 -Quick -Espresso -Testing

A look at how nested beforeEach and afterEach behave in the Quick testing framework.

Nimble: when to use waitUntil or toEventually

Fri May 05 2017 -Testing -Nimble -Swift

The Nimble matchers framework provides two ways assert expectations on asynchronous code, this post explores when to use one or the other.

XCTest closure based expectations

Wed Mar 22 2017 -Swift -XCTest -Testing

Testing async code is not simple, but XCTest provides us with all the required tool. This post shows how to wait for an expectation to be fulfilled based on a Swift closure.

How to use dependency injection for classes in Swift

Wed Mar 01 2017 -Swift -Testing

In Swift it is possible to pass a reference to a type itself, not just to an instance of it. This post shows how to use this capability to test legacy code.

Using Swift protocols to abstract third party dependencies and improve testability

Wed Mar 02 2016 -testing -swift

Third party code can be hard to test, but you can use Swift's protocols to abstract its details and improve testability

Getting Started With OHHTTPStubs

Tue Feb 23 2016 -Testing -iOS

Good unit tests are fast and deterministic. Testing code that hits the network could undermine this goal, but using OHHTTPStubs we can take back control of our tests. This post explores the advantages of stubbing the network, and provide a guide on how to do it with OHHTTPStubs.

Why hitting the network is bad for your test, and what to do about it

Tue Feb 16 2016 -Testing

In this post we are going to look at why hitting the network from your unit tests is a bad thing, and introduce some way to solve the problem.

Async Testing with Quick and Nimble

Wed Jan 27 2016 -Swift -Testing

A look at how to write tests for async code when using the Quick and Nimble Swift frameworks. This post is part of the Practical Testing in Swift series.

Testing Delegates in Swift with XCTest

Tue Jan 19 2016 -Swift -Testing -XCTest

In this second post of the Practical Testing in Swift we a look at strategies to test how objects call their delegate methods or set property on them.

Testing callbacks in Swift with XCTest

Tue Jan 12 2016 -Testing -XCTest -Swift

Prevent Unit Tests from Loading AppDelegate in Swift

Fri Jan 08 2016 -Xcode -Swift -Testing

How to prevent the unit test target from loading the AppDelegate and have faster tests execution.

Fixing Bugs Driven By Tests in Swift

Wed Oct 28 2015 -Testing -Swift -Acceptance Testing -UI Testing

Unit and acceptance test are powerful tools that can be used to identify and fix bugs. Let's see how using a bugged Swift app as an example.

/dev/world/2015 notes of a testing fanboy

Tue Sep 08 2015 -Testing -Tooling -Automation -Conferences

I attended /dev/world/2015 in Melbourne this week. It has been a great conference, full of very friendly and smart people. Being a test and automation fanboy I attended as many talks related to that topic as I could. These are my notes.

Explicit Dependencies, Swift Edition

Tue Aug 18 2015 -Testing -Software Design -Swift

A look at how to write classes and structs that expose their dependencies as initialization arguments in Swift.

Explicit Dependencies for Code with No Surprises

Tue Aug 11 2015 -Testing -Objective-C -Software-Design

Sometimes the idea we get when reading a class interface is different from what is actually going on inside its implementation, for example there could be several hidden dependencies. Making a class dependency explicit in its interface is a useful technique to make the code simpler to understand, and easier to test.

Testing Realm apps

Tue Jun 30 2015 -Testing

Realm is a mobile database that, unlike CoreData, is easy to test. In this post we will discuss some ideas on how to test an app using Realm as its database.

Specta global before and after each hooks (Updated)

Fri Apr 24 2015 -Testing -Specta

An interesting and powerful, yet not at all documented feature of Spetca are global beforeEach and afterEach hooks. In this post we'll see how to configure them, and how to blacklist classes from running them. Updated for version 0.5

Better tests with Specta

Tue Apr 14 2015 -Testing -Specta -XCTest

Writing unit tests for our iOS and OS X projects not only is important, but should be always part of the development cycle. As such the way we write the tests is as important, and having the option to write tests that easily explain their purpose can drastically increase the quality of the suite. Specta and Expecta are two libraries that provide a different way to writing tests than XCTest, let's see what we can gain by using such approach.

Xcode keyboard shortcuts for testing

Tue Apr 07 2015 -Testing -Xcode -Productivity

Keyboard shortcuts are easies way to start increasing your productivity. Let's look at how to run tests in Xcode without ever touching the mouse.

The state of iOS testing in 2015

Tue Mar 24 2015 -Testing -Acceptance Testing -Continuous Integration

In this post we'll look at the main tools and libraries available to write unit and acceptance tests for iOS and OS X applications, as well as the solutions to host Continuous Integration for our projects.

Specta global before and after each hooks

Thu Mar 19 2015 -Testing -Specta

An interesting and powerful, yet not at all documented feature of Spetca are global beforeEach and afterEach hooks. In this post we'll see how to configure them, and how to blacklist classes from running them.

How to run Xcode tests from the terminal

Last updated: Fri Jan 08 2021 -Testing -Xcode -Terminal -Automation

How to invoke xcodebuild to run the tests from the command line and how to format its output using xcbeautify or xcpretty

mokacoding

Hi I'm Gio I write here semi-regularly on software testing and TDD, productivity, and iOS development.

Get in touch if you're interested in working together.

AltStyle によって変換されたページ (->オリジナル) /