Testing in Java Part 1 – Basics

Different types of testing:

  1. System test / End to End test normally will be done via QA
  2. Aggregate Test / testing component to make sure the business functionalities with all the dependencies could be done as they supposed to. it took longer than unit test since it has a database to set up and tear down, or clean up some stuff, etc.
  3. Unit test / testing each individual functionality. no dependencies.

 

3 Stages every test case needs to have:

  1. ┬áprepare the environment for testing (preparing any requirement before actually testing the behaviour – it might happen in every method.)
  2. the behaviour to test (the actual function you want to test – if that’s too big, you’re testing a lot of functionalities and if something happened you need a way to find that between that complex tests)
  3. checking the result (Assertions)

making testing in orders might make dependencies between unit tests which don’t have any meaning other than, Aggregate testing instead of testing every individual function.

NOTE: every test methods in your test class, should only test one behaviour, even if preparing and function parts of couple test methods will be similar but and the differences will be in assertion parts, then it might show that you are testing differents parts/ behaviours of the function.

NOTE: Make your test methods names, expressing the behaviour of testing, make sure they expose what you want to test.

NOTE: One test class for one Class object.

NOTE: testing the throwing of an exception in the case of a failure of the application?

<br data-mce-bogus="1">

<strong>@Test(Expected=MyTypeOfException.class)</strong>

&nbsp;