If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

17. Unit testing

Review the presentation JUnit

Tasks

Create the classes to be tested

  1. Explore the jtm.activity17 package
  2. Implement the Student class similar to the Teacher class in the activity13 package
  3. Implement the StudentManager class, similar to the TeacherManager class
  4. You can simply copy-paste the methods and make the necessary changes
  5. Be aware that you can introduce errors here, as it is possible that not all the necessary changes are made correctly.

Create a new JUnit test

  1. In Package Explorer, right-click on the src/test/java folder and create a package called jtm.activity17.
  2. Right-click on the created package jtm.activity17 and select: New— New JUnit Test Case
  3. In the New JUnit Test case window:
    1. Check that the test version is: New JUnit 4 test,
    2. Check that the test location is: .../src/test/java,
    3. Check that the package is: jtm.activity17,
    4. Set the test name: DatabaseUnitTest1 (this name is important because it will be used by the automatic test test)
    5. If necessary, check setUpBeforeClass(), tearDownAfterClass(),
    6. If necessary, check setUp() and tearDown(),
    7. If necessary, check GenerateComments,
    8. Set the Class to be tested: jtm.activity17.StudentManager,
    9. Press Next.
  4. In the Test methods window:
    1. Check the StudentManager class to test all its methods,
    2. If necessary, check Create final method stubs,
    3. If necessary, check Create tasks for generated test methods,
    4. Click Finish.

Manual testing

  1. Select: Run— Run as— JUnit test to test this file as a simple unit test.
  2. Right-click the test (or package) in the Package Explorer and select: Coverage as– JUnit test to check the coverage of the tested classes.

Automated testing

Automated testing using the test's main() method

Automated testing and coverage reporting is performed by the DatabaseUnitTest.java test, which is compiled into the JTM.jar package.
To test how it will work manually, you can do the following.

  1. Create a public static void main(String[] args) method to allow the test to run as a Java application.
  2. Create the following body for this method:

    public static void main(String[] args) {
    DatabaseUnitTest dbUnitTest = new DatabaseUnitTest();
    dbUnitTest.test();
    }
  3. Select: Run— Run as...— Java application to check how your test will be executed from the automated test suite. You should see the coverage status, for example:

    ...
    *** Total test coverage is: xx% ***

    where xx is the actual coverage of the package being tested.

Automated testing using a modified Test Suite

  1. Open the AllTests.java class in the jtm.testSuite package
  2. Comment out unnecessary steps if necessary
  3. Run the test suite

Optional task

  1. Install EclEmma and check the test overlay.
  2. Select Help — Eclipse Marketplace..., name enter jd and press Install for the plugin Enhanced Class Decompiler.
    or

  3. Install and configure the JD-Eclipse decompiler
  4. Check how the Junit tests are implemented in the reference JTM.jar library (for example, jtm.activity13 as a (for your needs) test example in the package jtm.activity17)

Additional information


  

Created by Valdis Vītoliņš on 2025-01-28 17:44
Last modified by Valdis Vītoliņš on 2025-01-28 17:44
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License