show some examples of SwiftTesting
Generated on 8/5/2024
1 search
Here are some examples of Swift Testing from the WWDC sessions:
-
Declaring a Test:
- To declare a test, you add a
@Test
attribute to your function. You can provide a custom display name as an argument to the@Test
attribute, which helps make it easier to understand what the test is doing. You can verify the results using theexpect
macro, which allows you to write simple or complex Swift expressions. - Meet Swift Testing
- To declare a test, you add a
-
Parameterized Testing:
- Swift Testing allows you to run a single test function with many different arguments. For example, if you have an enumeration of ice cream flavors and need to check if a particular flavor contains nuts, you can use parameterized testing to cover all cases without writing separate test functions for each case.
- Go further with Swift Testing
-
Using Tags to Organize Tests:
- Swift Testing includes a flexible tagging system to help you organize your tests and test plans. You can use tags to selectively run tests across your test suite, such as tests that use a certain module or that run on a specific device.
- What’s new in Swift
-
Expectations and Traits:
- Expectations in Swift Testing leverage Swift language features and syntax to provide a highly expressive and concise interface. Traits allow you to specify information either per test or per suite, and they can be used to control when tests run or to associate tests with common characteristics.
- Meet Swift Testing
-
Migrating from XCTest:
- If you have existing XCTest tests, you might be wondering how to migrate them to Swift Testing. Swift Testing uses the
@Test
attribute to denote tests explicitly, supports more kinds of functions, and takes a different approach to parallelization by running in-process using Swift concurrency. - Meet Swift Testing
- If you have existing XCTest tests, you might be wondering how to migrate them to Swift Testing. Swift Testing uses the
For a deeper dive into Swift Testing, you can check out the full sessions:
Go further with Swift Testing
Learn how to write a sweet set of (test) suites using Swift Testing’s baked-in features. Discover how to take the building blocks further and use them to help expand tests to cover more scenarios, organize your tests across different suites, and optimize your tests to run in parallel.
What’s new in Swift
Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.
Meet Swift Testing
Introducing Swift Testing: a new package for testing your code using Swift. Explore the building blocks of its powerful new API, discover how it can be applied in common testing workflows, and learn how it relates to XCTest and open source Swift.
Platforms State of the Union
Discover the newest advancements on Apple platforms.