Tuesday, 29 August 2017

Why does my code throw a null pointer exception? - common reason #1 Redeclaration


TLDR; check that you haven’t redeclared a field as a variable in a setup method

FAQ - why does my code throw a null pointer exception - common reason #1 Redeclaration

  • Using @BeforeClass or @Before can setup data for use in tests
  • Any ‘variables’ we instantiate need to be ‘fields’ rather than variables
  • We want to instantiate them in the setup method rather than redeclare them