Setting useful Xcode behaviors for testing

Xcode has a feature called behaviors. With the use of behaviors and tabs, Xcode can show useful information depending on its state.

Open the Behaviors window by going to Xcode | Behaviors | Edit Behaviors. On the left-hand side are the different stages for which you can add behaviors (Build, Testing, Running, and so on). The following behaviors are useful when doing TDD.

The behaviors shown here are those that I find useful. Play around with the settings to find the ones most useful for you. Overall, I recommend using behaviors because I think they speed up development.

Useful build behaviors

When building starts, Xcode compiles the files and links them together. To see what is going on, you can activate the build log when the building starts. It is recommended that you open the build log in a new tab because this allows us to switch back to the code editor when no error occurs during the build. Select the Starts stage and check Show tab named. Put in the name Log and select in active window. Check the Show navigator setting and select Issue Navigator. At the bottom of the window, check Navigate to and select current log. After you have made these changes, the settings window should look like this:

Useful build behaviors

Build and run to see what the behavior looks like.

Testing behaviors

To write code, I have an Xcode tab called Coding. Usually, in this tab, the test is open on the left-hand side, and in the Assistant Editor on the right-hand side is the code to be tested (or in the case of TDD, the code to be written). It looks like this:

Testing behaviors

When the test starts, we want to see the code editor again. So, we add a behavior to show the Coding tab. In addition to this, we want to see the Test Navigator and debugger with the console view.

When the test succeeds, Xcode should show a bezel to notify us that all tests have passed. Go to the Testing | Succeeds stage, and check the Notify using bezel or system notification setting. In addition to this, it should hide the navigator and the debugger because we want to concentrate on refactoring or writing the next test.

In case testing fails (which happens a lot in TDD), Xcode should show a bezel again. I like to hide the debugger because usually it is not the best place to figure out what is going on in the case of a failing test. And in TDD, in most cases, we already know what the problem is. But we want to see the failing test. Therefore, check Show navigator and select Issue navigator. At the bottom of the window, check Navigate to and select first new issue.

You can even make your Mac speak the announcements. Check Speak announcements using and select the voice you like. But be careful not to annoy your coworkers. You might need their help in the future.

Now, the project and Xcode are set up, and we can start our TDD journey.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.124.143