dimanche 22 février 2015

Preconditions in Swift and Testing Them

In Java I can use frameworks like Guava to check method preconditions, for example like this:



public void doSomething(int index) {
Preconditions.checkArgument(index >= 3);
// do something
}


And I can then test them like this:



@Test(expected = IllegalArgumentException.class)
public void testDoSomething() {
sut.doSomething(2);
}


How can I do the same thing in Swift?


I know about Swift's assertions, but I don't know how you would test for them.


Aucun commentaire:

Enregistrer un commentaire