1

We didn't implement automated deployment yet to our Angular 7 project, so environment-based variables (e.g baseUrl) are changed manually, causing the application to crash after deployment a lot due to wrong variable values.

Does it make sense to write some environment-specific tests to ensure that the correct values are being passed and set and how to go about this (e.g. conditional statements based on node_env, separate test files for each environment, ...)?

Things I want to keep in mind are:

  • Code coverage
  • Applying DRY to not repeat tests that wouldn't be different based on different environments
  • Should I use E2E or unit tests or both for the mentioned purpose.
2
  • 1
    To me this is a valid question. Having to manually change the baseURL seems like a design flaw. It should be testes via unit testing yet again - if the variable is set manually there is not much to test, as the url is hardcoded.
    – Moro
    Commented May 31, 2019 at 8:58
  • @Moro I appreciate that. It definitely is, but in real life, I can't just automate everything, so I am trying to improve the application step by step, and for me the wrong values for things like baseURL are a huge headache, even with environment variables things can get missy. That's why I am posting the question so see the best way to ensure that these variables are set and are set correctly. Commented May 31, 2019 at 12:48

1 Answer 1

3

if it makes sense to write some environment-specific tests ?

Absolutely! This is also frequently the job of smoke tests which basically assert that the latest deployment was successfull with very simple tests such as 'can I reach the page or do I get a 404'

Testing the tests is an essential part of any quality automation system.
You should generally test the tests for:

  • Environment variables set correctly *
  • Page Object Duplicates
  • Page Object Orphans
  • Test Code complexity
  • Test code syntax and linting
  • Test code quality

In your case smoke tests and environment variable tests should be used.

*You'll need to think this through. Obviously static code 'does x = 1' does not respect different environments. Also you want to avoid statement like does url = x and username = y and password = z. Think through a system that forces you to update these items. Maybe check the update timestamp of the variables file, maybe use a deployment step or sha to do this.

Ultimately:

Automate the entire process. When you need variables for a given environment, make sure they have to be updated as an automated step of the deployment process.

3
  • I definitely need to automate the process, but this of course a long process. Meanwhile, I think smoke tests are good, I found a very good example letscodejavascript.com/v3/transcripts/lessons_learned/4#tabs. Just to be clear, when and where should I run the smoke tests? in a duplicate (staging server) environment or in the production environment? Commented May 31, 2019 at 12:46
  • 1
    The environment you are deploying to. If they fail you stop or rollback immediately Commented May 31, 2019 at 13:39
  • I.e. production in this case Commented May 31, 2019 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.