Skip to content

Unit testing

peasoupio edited this page Dec 11, 2020 · 1 revision

INV implemented a unit testing mechanism that allows the testing of your logics and a "breakpoint" debugging using your preferred IDE.

To start, take a look at this implementation from inv-public-repo.

inv-public-repo is the public REPO provided by peasoupio.

Start testing locally (following an existing example)

1. Extract sources

Start by extracting the following source using git: git clone https://github.com/peasoupio/inv-public-repo.git

2. Start your preferred IDE and import the sources

Here, we will be using IntelliJ (learn more here) We will import the net/http subfolder from the sources.

3. Configure your Groovy library

Open your Project Structure panel (File>Project Structure) and import your Groovy library. Configure Groovy library IntelliJ For more help, take a look at https://www.jetbrains.com/help/idea/getting-started-with-groovy.html

Make sure your are using a JDK version >= 11 Configure Groovy library IntelliJ

4. Configure INV

INV repo project overview

You must add inv-core to your module libraries.
Open the Module Settings panel pressing on F4. Clicking on the Problems panel, you should see something similar to this: Missing inv-core error

To correct the problem, add io.peasoup:inv-core using the Maven library panel: Add inv-core using Maven

Select your preferred version, thou the newest is always recommenced: Choose inv:core version

At this point, you should have no problem and your module libraries panel should look like this: Configure Groovy library IntelliJ

5. Run and Debug unit tests

Right-click on a test script, under the /test folder, and choose either Debug or Run Create unit test run configuration

IMPORTANT: For an efficient local execution, tests scripts should start with those lines:

@groovy.transform.BaseScript(io.peasoup.inv.testing.JunitScriptBase.class)
import org.junit.Test 
import static org.junit.Assert.*
  • First line will tell IntelliJ which base class to use, thus enabling the debugging feature.
  • Second line is somewhat required by the @Grab statement. Mostly, it removes @Test not found errors.
  • Third line add most of the Junit 4 asserting static methods.
    IMPORTANT: Those lines are NOT MANDATORY for an actual run using CLI or Composer. Their added values are only for an enchanced development experience.

A Run execution would look like this: Run INV unit test

A Debug, with a breaking point, would look like this: Debug INV unit test