Skip to content

API Testing Code Conventions

Standard Java Code convention is used as basis.

Project Tests Convention

Important: We have to cover actions for controllers with API tests - NOT user flow replicating business logic.

Test Structure Guidelines

ModuleGoalNaming/ExplanationComments
Test ClassMain class used to reflect verification for a FeatureA name of a controller + TestExample: class MissedAppointmentTest
Test MethodEndpoint response validationverify + actionExample: In the class MissedAppointment they are:
verifyListSortedByName()
verifyShowFilterByLocation()
verifyUpdateRightAllowed()
verifyUpdateNoAccess<Description>()
verifyUpdateAccess<Description>()
verifyDeleteAction()

In case there are two equal actions for the same controller add additional "marker" after "Action" word, e.g.:
verifyListActionAdd1
verifyListActionAdd2
Before MethodPrecondition to start testpublic void executePreconditions()Create all required entities. For example, for testing Procedure, create Provider and Patient
After MethodPostcondition to clean datapublic void executePostconditions()Delete entities created with a test. Set Location setting to a default.
AssertionsVerify response with expected dataMethod body() of ValidatableResponseOptions classSee example below
Utility ClassCommon methods which wrap set of rest-assured methods
DTO ClassDepict Json objects sent and received during test executionCreate two classes for each business entity: for create (post) and from response for update (put).Examples: PatientCreate, PatientUpdate, PaymentDistributionResponse
ConfigurationFiles containing info about app urls, db urls, 3rd parties urls etc..env
Suite for local test runTestNG xml contains test classes for runFile should be placed in "java" package and name starts from "suite".Example: suite-ahyre.xml
PackagingShould correspond packaging of ascend source codepackage com.henryschein.onlinepm.clinical

Assertions Example

Example using the body() method of ValidatableResponseOptions class:

baseRequestSpecification
    .when()
    .pathParam("patientId", patientId)
    .get(PROCEDURE + procedureId)
    .then()
    .log().all()
    .body("amount", is(100.0F))
    .body("practiceProcedure.id", isA(Long.class))
    .body("xfer.primaryInsurance", is(100.0F));

Key Principles

  1. Test Class Structure: Test class should contain only test methods which are related to actions for a specific controller (test class has the controller's name).

  2. Focus on API Actions: Cover controller actions with API tests, not user flow business logic.

  3. Consistent Naming: Follow the naming conventions for test classes and methods to maintain consistency across the test suite.

  4. Data Cleanup: Always implement postconditions to clean up test data and restore default settings.

  5. DTO Separation: Maintain separate DTO classes for create operations (POST) and update operations (PUT) to clearly distinguish between request and response structures.