Skip to content
jabiercoding edited this page Feb 3, 2016 · 15 revisions

Software testing exercises

Basics

JUnitExample

Let's see how a JUnit looks like. We have a Utils class with some methods to be tested.

  • tests is a separated source folder, this is a good practice. If we use the same package name we can access and test protected methods
  • @Test is the annotation to be included before the test method. The method can have any name you want
  • We test normal cases and those that we think that can be problematic (e.g. addition overflow)
  • Test suits (MyTestSuite.java) can group tests
  • Right click a test method, a test java file or a test suite -> Run as... -> JUnit Test
  • In the ReverseTest.java there are some commented lines. Uncomment them to see the effect of the annotations @BeforeClass @AfterClass @After @Before . Those are important when dealing with time or resource consuming tasks (e.g. database connections) that need to be done after or before running the tests
Clone this wiki locally