Skip to content

best practices to set env variables #287

Answered by LukeSavefrogs
aubertaa asked this question in Q&A
Discussion options

You must be logged in to vote

TL;DR;

It depends on how you want to handle your tests.

Personal preference

Personally, i like to follow the following rules:

  • If it's an environment variable used throughout the whole test (i.e. the path to a specific file) i place it at global scope (outside of every block);
  • If it's an environment variable that needs to be reset before every test (i.e. a counter of some sorts) i place it in the BeforeAll or BeforeEach hooks;
  • If it's going to be used only for a specific test (i.e. a DEBUG to test the verbosity) i place it in the Describe or It blocks;

But as i've said before, it really depends on what you're trying to make.

Demonstration

In the following example i have taken into consid…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aubertaa
Comment options

@LukeSavefrogs
Comment options

@aubertaa
Comment options

Answer selected by aubertaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants