CODEFRESH.IO DOCUMENTATION

Codefresh is a Docker-native CI/CD platform.

Instantly build , test and deploy Docker images.

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Unit Tests

With Codefresh, you can easily set your unit tests to run on every build.
You configure your unit test script inside the service's settings page or YML file.

Run Unit Tests from the Codefresh UI

  1. Click Pipelines (gear icon) on your service.
  1. Define your unit test script.
For example we input command(will print the date) - echo $(date)

For example we input command(will print the date) - echo $(date)

IMPORTANT:

Make sure your testing frameworks are installed in your service Docker image. For full documentation on Dockerfile commands, visit the Docker documentation.

  1. Click Save and Build the project.

What to do next:

Expand the Running Unit Tests section to view the actions taken during the test.

Run unit tests using the codefresh.yml file

What is a YAML file?

For more information about the codefresh.yml file, click here.

  1. Add a unit-test step to your codefresh.yml file.
    Example:
version: '1.0'

steps:
  build-prj-name:
    type: build
    description: codefresh example
    image-name: codefreshexamples/expressangular
    dockerfile: Dockerfile
    tag: latest
  unit-tests:
    image: node:latest # image that contains installed tools for performing test commands
    commands:
      - echo $(date)
  1. In your pipeline switch to the Use YML build
  1. Click Save and Build

What to do next:

Expand the Running Unit Tests section to view the actions taken during the test.

Run tests with composition

A Composition is a number of containers that define a micro-services based application. For example, it can include all services, or a sub-subset of services.

  1. Select the 'Run tests with composition' check box.
  1. Select a composition.
  1. There are two ways to run with composition:
    • Attach to Composition - The image will be attached to the composition as a new service named cf_unit_test and the script will run inside it.
    • Replace service - Choose a candidate service from your composition which Codefresh will use to run your unit tests on. Notice that the image of that candidate will be replaced with the built image from the previous step and the command will be overridden by the unit test script.
Selecting the Replace Service option

Selecting the Replace Service option

  1. In Pipelines your service click Save and build your project.

Result: In the log of process “Unit tests”, we can see which actions the test makes.

Unit Tests