Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Testing

Jason Reilly edited this page Oct 12, 2021 · 12 revisions

Development Testing

The tests for the CAM-KP-API project have been split in to 2 groups: Unit & Integration. The Unit tests can be found in https://github.com/NCATS-Tangerine/cam-kp-api/tree/master/src/test/scala & the Integration tests can be found in https://github.com/NCATS-Tangerine/cam-kp-api/tree/master/src/it/scala. The primary difference between Unit & Integration tests is that Unit tests are intended to test parts of the code that do not make calls out other services (eg, getting Biolink data, RESTful calls to the Blazegraph datastore, etc), whereas the Integration tests do.

CI Testing

The CAM-KP-API project is currently configured to run the included Unit tests via a Github Action found here. A refined set of Integration Tests are also run via a Github Action found here. The Integration Tests used with a Github Action go further than the other standard Integration Tests insomuch as they specify a specific identifier in the TRAPI query and assert that the results match.

Running Unit tests

The Scala Build Tool (SBT) is the library used to manage development specific tasks in a CAM-KP-API project. The following are a few useful commands to run one or more of the Unit tests:

cam-kp-api$ sbt test
cam-kp-api$ sbt testOnly org.renci.cam.test.QueryServiceTest

Running Integration tests

Note that the Integration tests depend on a locally deployed Docker container image of the CAM-KP-API project. As such, a command to build and deploy an image to a local Docker container is included.

cam-kp-api$ sbt docker:stage docker:publishLocal
cam-kp-api$ sbt it:test
cam-kp-api$ sbt it:testOnly org.renci.cam.it.QueryServiceTest

Test Code Coverage

A report showing how well the Unit tests cover the code can be found in a Code Coverage report here: https://ncats-tangerine.github.io/cam-kp-api/scoverage-report/

Testing a Query Message via curl

Write your TRAPI formatted query to a file called 'query.json'. Here is an example of what the contents should resemble:

{
  "message": {
    "query_graph": {
      "nodes": {
        "n0": {
          "category": "biolink:Gene"
        },
        "n1": {
          "category": "biolink:BiologicalProcess"
        }
      },
      "edges": {
        "e0": {
          "predicate": [
            "biolink:has_participant"
          ],
          "subject": "n1",
          "object": "n0"
        }
      }
    }
  }
}

Then, to run that query & then again with a results limit:

$ curl -d @query.json https://stars-app.renci.org/cam-kp/query
$ curl -d @query.json https://stars-app.renci.org/cam-kp/query?limit=10

Alternatively, one could execute a curl command to run a sample query against a locally running instance of the project:

$ docker run -p 8080:8080 -d renciorg/cam-kp-api:0.1
$ curl -d @query.json http://localhost:8080/query?limit=10