Unit Testing and Embedded Swift

Do we have a proposed way forward for unit testing with embedded swift?

The swift testing proposal references the challenge of supporting embedded swift but I can't find any subsequent information about how this is being progressed?

We would like to be able to use embedded swift but are constrained by the challenges of not having a native test framework to work with.

2 Likes

Hi Terry,

Good question. One that I have asked myself as well.

I'll put this on the testing workgroup agenda to discuss.

KR Maarten

1 Like

Thanks. I would envision that there are at least three scenarios that need consideration:

  1. Testing Swift 'business logic' on the host machine - compiling for the host and executing tests locally as part of the build.
  2. Testing on target hardware - cross-compiling and then launching a test suite on target hardware and collecting results.
  3. Testing on emulated hardware - cross-compiling and then launching a test suite on a simulator / emulator running on the host.

There are some build-related challenges that creep in too. For example, ESP32-builds are leveraging the IDF build process, so unit tests need to be invoked as part of that build pipeline rather than as per SwiftPM norms.

Practically speaking, it is likely that teams will need to be able to use more than one of the options above in order to get appropriate coverage, since each approach has different limitations with regard to external dependencies like FreeRTOS libraries or hardware support. This introduces a need for multiple build targets.

2 Likes

We spoke about this in our workgroup session.

And YES: supporting embedded platforms with Swift Testing is definitely something we want to provide in the future. When? We really don't know yet. It's not something that is very easy.

@grynspan created an issue to track progress on GitHub: Add support for Embedded Swift · Issue #977 · swiftlang/swift-testing · GitHub
I recommend you subscribe to that issue (I did as well) to get updates on progress.

Once we have more concrete news, we'll off course share it on the forum.

1 Like