Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Unit Testing with Throws in Swift 2.0

DZone's Guide to

Unit Testing with Throws in Swift 2.0

Some important things to note about functions that include a throws declaration.

· Mobile Zone
Free Resource

Get gorgeous, multi-touch charts for your iOS application with just a few lines of code.

I've been working very slowly on a Swift version of Playlist Export, and today I finally got around to updating the project to Swift 2.0.  Luckily I wrote test cases for much of the logic to manage the export process, so I had some level of confidence that I would know if I broke anything.

However, after I got the project to compile, only one of the test cases ran.  No errors or other indication why all the other cases were ignored.

I did finally figure out that if you your test case has a throws clause, it will be IGNORED.

So: 

testPlaylistNameExtension() throws {
    ...
}

will silently be ignored, which for a test case is a pretty bad scenario.  But if you handle the error in the function and change it to:

testPlaylistNameExtension() {
    ...
}

then everything is just fine.  So if you have test in Swift 2.0 that are ignored or not executed, check to see if you have a throws in the function declaration.

.Net developers: use Highcharts, the industry's leading interactive charting library, without writing a single line of JavaScript.

Topics:
swift ,testing

Published at DZone with permission of Eric Daugherty, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}