Testing

🕓 15 minutes

What you’ll learn#

How to create, run and analyse tests for the application components in the CodeNOW environment.

  • Writing tests for the application is an essential part of the application development process.
  • Here are some benefits that you gain by testing your application:
    • You don’t have to spend the time manually testing the code yourself.
    • You can make changes to the code without worrying if something is broken.
    • If something went wrong, you are able to detect the problematic part by looking into the tests.
    • Tests provide documentation for what your code is actually meant to do.

Prerequisites#

Overview#

CodeNOW uses the Karate tool for testing purposes.

Find the "Testing&Quality Management" section in the sidebar menu, click on the "Testing" and go to the "Test Use Cases" option.

  • Here you will see two sections:
    • Select an Application
      • You can select an existing application to create, run or analyse test use cases.
    • Custom Applications
      • You can create test cases for an external application.
go_to_testing

testin_overview

Select an Existing Application#

  1. Select an existing application and click on the "Add Test Repository" button on the right.
  • After a little while, the "Show Test Use Case" button will appear.
add_test_repo

show_test_use_case

  1. Click on the "Show Test Use Case".
  • Here you will see some information regarding the existing tests for the selected application.
    • How to clone your test repository
    • Test components' builds.
    • Test folders for each of the application components.
test_use_case_overview

  1. The "Clone your Test Repository" section describes how to clone a test repository using SSH or via HTTP(S) into the local environment.
clone_repo

  1. The "Component Builds" section shows all the existing components inside the chosen application.
  • For each test component, you can see the latest test package build version.
  • If the test package of the particular component hasn't been built yet, you can click on the "Build" button on the right.
  • You need to compile the sources in order to build the components which could be used by the end consumer.
component_build

build

  1. Down below you see all the test packages for every application component.
  • It shows the test name and count.
  • If you click on the "Detail" button, you can see the use case detail, tests and test results.
detail

use_case_detail

  • If you click on the "Detail" button in the "Use Case Tests" section, in the "Feature Content" section you can see the test code for the selected test case.
use_case_test_detail

feature_content

  1. If you want to run the selected test package, you can click on the "Run" button.
run

  • You will be redirected to a page, where you should select an environment and a use case version.
  • Then click on the "Deploy" button.
exec_config

Use Case Test Results#

CodeNOW uses the Cucumber tool to generate test reports.

How to Find#

To see the test results analysis:

  1. Select the application component.
  2. Click on the "Details" button on the right and you will be redirected to a Use Case Detail page.
  3. In the section "Use Case Test Results" select one of the test results and click the "Details" button.
test_results_detail

Overview#

Here, you are able to see an analysis of the features, tags, steps and failures on the selected use case run report.

report

  1. Features
  • The graphs in this page show the passing and failing statistics for features.
  • The table shows detailed information for the tested feature including:
    • Passed, failed, skipped, pending and undefined steps.
    • Passed and failed scenarios.
    • Duration and status for the features.
feature

  1. Tags
  • The graph shows passing and failing statistics for tags.
  • The detailed information on each tag is collected into the table below the graph.
tags

  1. Steps
  • The following table shows the step statistics for this build.
  • The list below is based on the results. If a step does not provide information about the result then it is not listed below.
  • Additionally, @Before and @After are not counted because they are part of the scenarios, not steps.
steps

  1. Failures
  • The following summary displays the scenarios that failed.
failures

Create a Custom Application#

If you want to test an external application that doesn't run in the CodeNOW environment, you can add a custom test application for this purpose.

go_to_lib

Fill in the application name and add the required number of components. Then click on the "Confirm" button.

go_to_lib

Now you can clone the created test repository to the local environment, write tests and run them in the CodeNOW environment.

  • Don't forget to add correct values, so the tests can reach your application.
  • The process continues with STEP 2 of the "Select an Existing Application" section.

Simple Karate test example#

Basic Keywords#

  • Feature: List of scenarios.
  • Scenario: Business rule through a list of steps with arguments.
  • Given: Some precondition step
  • When: Some key actions
  • Then: To observe outcomes or validation
  • And,But: To enumerate more Given,When,Then steps
  • Examples: Container for a table
  • Background: List of steps run before each of the scenarios

Example#

  • This simple test example consists of two parts:
    • The first test creates a new cat entity with the name of "Fluffy". It says: after making a POST request, you should get status 201 and the response must contain a non-null id and the name "Fluffy".
    • The second one is a simple GET for a cat that was created in a previous part of the test.
Scenario: Create and retrieve cat
Given url 'http://cat-api-url/cats'
And request {name: 'Fluffy'}
When metod post
Then status 201
And match response == {id: '#notnull', name: 'Fluffy'}
Given path response.id
When method get
Then status 200
  • If you are creating a test for a CodeNOW component, then you don’t need to specify the given url or path. The CodeNOW will automatically add the right values during the building process.
  • On the other hand, if you create a test package and write a test for a custom application, then for the test to be able to reach its testing target, you must specify the "given url" value.

What's next?#

See our other manuals: