Test Your Command-Line Tool In Xcode

Test Your Command-Line Tool In Xcode

Β·

1 min read

Manual testing in the terminal is straightforward, but you might struggle with one of the following challenges when running your program from Xcode.

Challenges

Challenge: pass required arguments

If your command-line tool defines mandatory arguments, you might feel stuck as no arguments are passed per default. Another challenge you might face is that you want to simulate that the program was started from a certain directory.

No worries. In this blog post, I will show you how to

  1. Pass Arguments On Launch
  2. Set a Custom Working Directory

Pass Arguments On Launch

Edit Scheme

Open "Edit Scheme".

Pass Arguments On Launch

You can specify the arguments passed on launch in the "Arguments" tab of the Run phase.

Positive test result for passing arguments on launch

Set Custom Working Directory

The $(BUILD_PRODUCTS_DIR) is used as the working directory per default. To change that, open "Edit Scheme". You can specify a custom working directory in the "Options" tab of the Run phase.

Set custom working directory in scheme

Positivite test result for custom working directory

Demo