detox
is globally available in every test file, though currently it is only used in the setup/init file.
NOTE: detox is test runner independent, and we encourge you to choose your own test runner, but for the sake of demonstration we will use
mocha
's syntax.
The setup phase happens inside detox.init()
. This is the phase where detox reads its configuration, starts a server, loads its expection library and starts a simulator.
const config = require('../package.json').detox;
before(async () => {
await detox.init(config);
});
By default await detox.init(config);
will launch the installed app. If you wish to control when your app is launched, add {launchApp: false}
param to your init.
const config = require('../package.json').detox;
before(async () => {
await detox.init(config, {launchApp: false});
});
NOTE: Detox 6.X.X will introduce a breaking change , setting
launchApp
tofalse
by default. In order to prevent any breaking changes to your tests when you upgrade (and if you still would likeinit
to launch the app for you) do the following:
before(async () => {
await detox.init(config, {launchApp: true});
});
The cleanup phase should happen after all the tests have finished. This is the phase where detox-server shuts down. The simulator will also shut itself down if --cleanup
flag is added to detox test
after(async () => {
await detox.cleanup();
});