Tips and Tricks for Using UISpec with API Data

I need to start making TDD for this iPhone project. The problem is that it uses the API data quite heavily.

I am looking for a good tutorial / guide / example project that shows how to implement TDD, how to set up a database before each test runs on iPhone. I tend to use UISpec, but I'm ready to take a look at some other test suite if it does it better. Also, the project already includes RestKit, which uses UISpec for its own testing, so UISpec is already included in the Xcode project.

+4
source share
1 answer

I am the lead developer of the RestKit project, and I would recommend that you use non- UISpec for testing. Using RestKit UISpec (more precisely, an abridged version with high customization) is an artifact from the very beginning of development - I used UISpec for functional testing and did not dare to transfer so many libraries. UISpec is essentially a failure these days, and I switched to using KIF from Square for my user interface / functional testing.

For unit testing new projects, I like Kiwi ( https://github.com/allending/Kiwi ) because it sits on top of the built-in SenTestingKit and provides RSpec-style tests. Cedar ( https://github.com/pivotal/cedar ) from Pivotal Labs and GHUnit ( http://gabriel.github.com/gh-unit/ ) are also solid. RestKit itself is likely to move to UISpec in the near future.

Now about how to set up a database for your tests. If you look in the RKSpecEnvironment.h / m files in RestKit, there are many useful methods for unit testing. Assuming you are using integration with RestKit Core databases, the RKSpecNewManagedObjectStore () method will destroy the Core Data environment and set up backups using a clean database, removing persistent storage.

RestKit's own unit tests can provide some good reference (besides the above testing issues) about how to block API data. The RKSpecResponseLoader class is useful for turning asynchronous REST requests into procedural steps (it serves as a delegate for RKObjectLoader and will rotate the loop to wait for the request to load) with which you can test. Thus, the general template is to clear the state of the database, configure any objects that you need / expect, and then interact with the API and approve against the results or the new state in Core Data.

+12
source

Source: https://habr.com/ru/post/1369315/


All Articles