# Activity 17: Generate JUnit tests

To generate JUnit test cases for for the Java implementation of the vending machine, an adapter is needed between the test cases and the system under test. The test case generator for JUnit assumes a file Adapter.java is available in a package with the same name as the generated package that contains TestCases.java, i.e., “test.[name of component or interface]”. For interface IService it can be found at location src/test.IService.

For the vending machine, this file has already been written manually.

- Extend project file VendingMachine.prj, which already contains task ReachabilityGraph_IService, with the following task:

      Generate Test {
          Test_IService for task ReachabilityGraph_IService {
              java: {
              }
          }
      }

  Note that this task uses the results of task ReachabilityGraph_IService; to speed up the generation, option "debug" of this task may be removed.

- Execute the CommaSuite workflow on VendingMachine.prj and inspect the resulting file TestCases.java in folder src-gen/tes/IService.

- Ensure JUnit 5 is available (this has already been done for the vending machine):

      Right-click on project, select Build Path > Configure Build Path;
      select tab Libraries > Add Library > select JUnit5

- Define src-gen as source folder:

      Right-click on project, select Build Path > Configure Build Path;
      select tab Source > Add Folder > select src-gen

- Since the adapter also starts logging the tests as .events files, create a folder EventFilesTests to store these traces (right click on the vending machine project, select New > Folder).

- Run the test cases, by right clicking on TestCases.java and selecting Run As > JUnit Test.

  - Note that the .events files in EventFilesTests might be checked by monitoring as a kind of consistency check.