Unit testing

How to ensure high quality components.

We recommend adding unit tests to all of your components in a project as soon as possible. Implementing unit tests not only ensures that your component works, but it also makes the project more maintainable in the long run as you will be notified when a component breaks.

This page describes how to add a unit test to your component.

Create unit test

Below is an example of how to add a unit test to a Viash component.

#!/bin/bash

## VIASH START
meta_executable="target/example_bash"
## VIASH END

echo ">>> Create input test file"
echo "foo" > foo.txt

echo ">>> Run executable"
$meta_executable --input foo.txt --output bar.txt

echo ">>> Check whether output file exists"
[[ -f bar.txt ]] (echo "Output file could not be found!" && exit 1)

echo ">>> Check whether input and output file are the same"
cmp foo.txt bar.tx (echo "Input and output files are different!" && exit 1)

echo ">>> Test finished successfully"
using System;
using System.IO;
using System.Diagnostics;

// VIASH START
var meta = new {
  executable = "target/example_csharp"
};
// VIASH END

string inputPath = "foo.txt";
string outputPath = "bar.txt";
string content = "hello\nthere\n";

Console.WriteLine(">>> Create input test file");
File.WriteAllText(inputPath, content);

Console.WriteLine(">>> Run executable");

var startInfo = new ProcessStartInfo(meta.executable)
{
    Arguments = $"--input {inputPath} --output {outputPath}",
    UseShellExecute = false,
    RedirectStandardOutput = true,
    CreateNoWindow = true
};
using(var cmd = Process.Start(startInfo))
{
    cmd.WaitForExit();
}


Console.WriteLine(">>> Check whether output file exists");
if (!File.Exists(outputPath)) {
    Console.WriteLine("Output file was not found");
    Environment.Exit(1);
}

Console.WriteLine(">>> Check whether input and output file are the same");
var outputLines = File.ReadAllText(outputPath);
if (content != outputLines) {
    Console.WriteLine(
        "Input and output should be the same\n" +
        $"expected content: {content}\n" +
        $"found: {outputLines}\n"
    );
    Environment.Exit(1);
}

Console.WriteLine(">>> Test finished successfully");
const fs = require('fs');
const child_process = require('child_process');

// VIASH START
let meta = {
  'executable': 'target/example_js'
};
// VIASH END

const inputPath = 'foo.txt';
const outputPath = 'bar.txt';
const content = 'hello\nthere\n';

console.log('>>> Create input test file');
fs.writeFileSync(inputPath, content, 'utf8');

console.log('>>> Run executable');
const cmdArgs = [
  '--input', inputPath,
  '--output', outputPath
];
const child = child_process.spawnSync(meta["executable"], cmdArgs);
if (child.error) {
  console.error(`Error: ${child.error}`);
  process.exit(1);
}

console.log('>>> Check whether output file exists');
if (!fs.existsSync(outputPath)) {
  console.error('Output file was not found');
  process.exit(1);
}

console.log('>>> Check whether input and output file are the same');
const outputLines = fs.readFileSync(outputPath, 'utf8');
if (content !== outputLines) {
  console.error(
    `Input and output should be the same\n` +
    `expected content: ${content}\n` +
    `found: ${outputLines}\n`
  );
  process.exit(1);
}

console.log('>>> Test finished successfully');
import subprocess
import os

input_path = "foo.txt"
output_path = "bar.txt"
content = "hello\nthere\n"

## VIASH START
meta = {
  "executable": "target/example_python"
}
## VIASH END

print(">>> Create input test file")
with open(input_path, "w") as file:
  file.write(content)

print(">>> Run executable")
cmd_args = [
  meta["executable"],
  "--input", input_path,
  "--output", output_path
]
subprocess.run(cmd_args, check=True)

print(">>> Check whether output file exists")
assert os.path.exists(output_path), "Output file was not found"

print(">>> Check whether input and output file are the same")
with open(output_path, "r", encoding="utf8") as file:
  output_lines = file.read()

assert content == output_lines, \
  "Input and output should be the same" \
  f"expected content: {content}" \
  f"found: {output_lines}"

print(">>> Test finished successfully")
## VIASH START
meta <- list(
  "target/example_r"
)
## VIASH END

input_path <- "foo.txt"
output_path <- "bar.txt"
content <- c("hello", "there")

cat(">>> Create input test file\n")
writeLines(content, input_path)

cat(">>> Run executable\n")
system2(
  meta$executable,
  c(
    "--input", input_path,
    "--output", output_path
  )
)

cat(">>> Check whether output file exists\n")
if (!file.exists(output_path)) {
  stop("Output file was not found")
}

cat(">>> Check whether input and output file are the same\n")
output_lines <- readLines(output_path)

if (!identical(content, output_lines)) {
  stop(paste0(
    "Input and output should be the same\n",
    "expected content: ", content, "\n",
    "found: ", output_lines, "\n"
  ))
}

cat(">>> Test finished successfully\n")
import scala.sys.process._
import java.nio.file.{Files, Paths}
import scala.io.Source

// VIASH START
case class ViashMeta(executable: String)
val meta = ViashMeta(
  "target/example_scala"
)
// VIASH END
val inputPath = Paths.get("foo.txt")
val outputPath = Paths.get("bar.txt")
val content = "hello\nthere"

println(">>> Create input test file")
Files.write(inputPath, content.getBytes("UTF-8"))

println(">>> Run executable")
s"${meta.executable} --input $inputPath --output $outputPath".!

println(">>> Check whether output file exists")
assert(Files.exists(outputPath), "Output file not found")

println(">>> Check whether input and output file are the same")
val outputLines = Source.fromFile(outputPath.toFile()).getLines.mkString("\n")
assert(
  content == outputLines, 
  s"""Output not the same
expected: '$content'
found: '$outputLines'
""".stripMargin
)

println(">>> Test finished successfully")
  1. Create an input file “foo.txt” with some sample content.
  2. Run an executable file specified in the “meta” dictionary with the arguments “–input foo.txt” and “–output bar.txt”.
  3. Check whether the output file “bar.txt” exists.
  4. Check whether the content of the output file is the same as the content of the input file.
  5. If both checks pass, the script prints “Test finished successfully”.
Important

A test script doesn’t need to be written in the same scripting language as the main script, as long as all of the required dependencies are available. This means the main script could be written in R, but the unit test could be written in Bash.

Add test to config

Next, we need to add the unit test to the test_resources section in the Viash config.

functionality:
  name: example_bash
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: bash_script
      path: script.sh
  test_resources:
    - type: bash_script
      path: test.sh
platforms:
  - type: docker
    image: bash:4.0
  - type: native
  - type: nextflow
functionality:
  name: example_csharp
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: csharp_script
      path: script.csx
  test_resources:
    - type: csharp_script
      path: test.csx
platforms:
  - type: docker
    image: ghcr.io/data-intuitive/dotnet-script:1.3.1
  - type: native
  - type: nextflow
functionality:
  name: example_js
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: javascript_script
      path: script.js
  test_resources:
    - type: javascript_script
      path: test.js
platforms:
  - type: docker
    image: node:19-bullseye-slim
  - type: native
  - type: nextflow
functionality:
  name: example_python
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: python_script
      path: script.py
  test_resources:
    - type: python_script
      path: test.py
platforms:
  - type: docker
    image: python:3.10-slim
  - type: native
  - type: nextflow
functionality:
  name: example_r
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: r_script
      path: script.R
  test_resources:
    - type: r_script
      path: test.R
platforms:
  - type: docker
    image: eddelbuettel/r2u:22.04
  - type: native
  - type: nextflow
functionality:
  name: example_scala
  description: A minimal example component.
  arguments:
    - type: file
      name: --input
      example: file.txt
      required: true
    - type: file
      name: --output
      direction: output
      example: output.txt
      required: true
  resources:
    - type: scala_script
      path: script.scala
  test_resources:
    - type: scala_script
      path: test.scala
platforms:
  - type: docker
    image: sbtscala/scala-sbt:eclipse-temurin-19_36_1.7.2_2.13.10
  - type: native
  - type: nextflow

Note that if you can add multiple unit tests to the test_resources section, they will all be evaluated. You can also add other resources, similar to what is described in the page on adding resources.

Run the unit test

You can run the unit test as follows:

viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_bash4620173817820031937'
====================================================================
+/tmp/viash_test_example_bash4620173817820031937/build_executable/example_bash ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_bash:test' with Dockerfile
[info] Running 'docker build -t example_bash:test /tmp/viash_test_example_bash4620173817820031937/build_executable -f /tmp/viash_test_example_bash4620173817820031937/build_executable/tmp/dockerbuild-example_bash-rGm7Id/Dockerfile'
Sending build context to Docker daemon  37.38kB

Step 1/6 : FROM bash:4.0
4.0: Pulling from library/bash
8a49fdb3b6a5: Pulling fs layer
011a3955de72: Pulling fs layer
e7e50c41cbf1: Pulling fs layer
e7e50c41cbf1: Verifying Checksum
e7e50c41cbf1: Download complete
011a3955de72: Download complete
8a49fdb3b6a5: Verifying Checksum
8a49fdb3b6a5: Download complete
8a49fdb3b6a5: Pull complete
011a3955de72: Pull complete
e7e50c41cbf1: Pull complete
Digest: sha256:7fe064540034d08ec7019b23f44af13b785d9fd630a91fd9fd2b4517e561525a
Status: Downloaded newer image for bash:4.0
 ---> 57a8199dc6a3
Step 2/6 : ENTRYPOINT []
 ---> Running in dd0394157acb
Removing intermediate container dd0394157acb
 ---> e63abd181b52
Step 3/6 : RUN :
 ---> Running in 543654fe5179
Removing intermediate container 543654fe5179
 ---> a4b1f8f1da30
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_bash"
 ---> Running in 9484a711bfa4
Removing intermediate container 9484a711bfa4
 ---> 08b993aed8dd
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:33:30Z"
 ---> Running in 11803a16f79a
Removing intermediate container 11803a16f79a
 ---> 68efb4e74562
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 7c13f99f5359
Removing intermediate container 7c13f99f5359
 ---> 1b9f7700dec3
Successfully built 1b9f7700dec3
Successfully tagged example_bash:test
====================================================================
+/tmp/viash_test_example_bash4620173817820031937/test_test/test_executable
>>> Create input test file
>>> Run executable
Copying 'foo.txt' to 'bar.txt'.
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory
viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_csharp1220753917135637953'
====================================================================
+/tmp/viash_test_example_csharp1220753917135637953/build_executable/example_csharp ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_csharp:test' with Dockerfile
[info] Running 'docker build -t example_csharp:test /tmp/viash_test_example_csharp1220753917135637953/build_executable -f /tmp/viash_test_example_csharp1220753917135637953/build_executable/tmp/dockerbuild-example_csharp-bLvccb/Dockerfile'
Sending build context to Docker daemon  36.86kB

Step 1/6 : FROM ghcr.io/data-intuitive/dotnet-script:1.3.1
1.3.1: Pulling from data-intuitive/dotnet-script
df9b9388f04a: Pulling fs layer
3ae3a38ed752: Pulling fs layer
d772c6b09cca: Pulling fs layer
2c56128c63bd: Pulling fs layer
6c2be9941089: Pulling fs layer
5a0c86bcd85d: Pulling fs layer
5e733ff9c308: Pulling fs layer
4937da28ea60: Pulling fs layer
16def9f17d8d: Pulling fs layer
03ac08f8f1d3: Pulling fs layer
2c56128c63bd: Waiting
6c2be9941089: Waiting
5a0c86bcd85d: Waiting
5e733ff9c308: Waiting
4937da28ea60: Waiting
16def9f17d8d: Waiting
03ac08f8f1d3: Waiting
df9b9388f04a: Verifying Checksum
df9b9388f04a: Download complete
3ae3a38ed752: Verifying Checksum
3ae3a38ed752: Download complete
2c56128c63bd: Verifying Checksum
2c56128c63bd: Download complete
d772c6b09cca: Verifying Checksum
d772c6b09cca: Download complete
df9b9388f04a: Pull complete
6c2be9941089: Verifying Checksum
6c2be9941089: Download complete
5e733ff9c308: Verifying Checksum
5e733ff9c308: Download complete
16def9f17d8d: Verifying Checksum
16def9f17d8d: Download complete
03ac08f8f1d3: Verifying Checksum
03ac08f8f1d3: Download complete
4937da28ea60: Verifying Checksum
4937da28ea60: Download complete
5a0c86bcd85d: Verifying Checksum
5a0c86bcd85d: Download complete
3ae3a38ed752: Pull complete
d772c6b09cca: Pull complete
2c56128c63bd: Pull complete
6c2be9941089: Pull complete
5a0c86bcd85d: Pull complete
5e733ff9c308: Pull complete
4937da28ea60: Pull complete
16def9f17d8d: Pull complete
03ac08f8f1d3: Pull complete
Digest: sha256:d95bf2a2b3e095e5b02960ab4ddd4674d798a1493ed0dc5cf427c77a5ed90ed3
Status: Downloaded newer image for ghcr.io/data-intuitive/dotnet-script:1.3.1
 ---> 1102243946ae
Step 2/6 : ENTRYPOINT []
 ---> Running in 6f1f0be05110
Removing intermediate container 6f1f0be05110
 ---> 964d2978cb65
Step 3/6 : RUN :
 ---> Running in fd6ee1e1cc1c
Removing intermediate container fd6ee1e1cc1c
 ---> 2c698a4e2770
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_csharp"
 ---> Running in 3ef55f68a180
Removing intermediate container 3ef55f68a180
 ---> 0adcfd544947
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:33:42Z"
 ---> Running in 4b95562397ef
Removing intermediate container 4b95562397ef
 ---> 69da6dbb1064
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 2f308e375635
Removing intermediate container 2f308e375635
 ---> a5f30619812b
Successfully built a5f30619812b
Successfully tagged example_csharp:test
====================================================================
+/tmp/viash_test_example_csharp1220753917135637953/test_test/test_executable
>>> Create input test file
>>> Run executable
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory
viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_js8472287997916680870'
====================================================================
+/tmp/viash_test_example_js8472287997916680870/build_executable/example_js ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_js:test' with Dockerfile
[info] Running 'docker build -t example_js:test /tmp/viash_test_example_js8472287997916680870/build_executable -f /tmp/viash_test_example_js8472287997916680870/build_executable/tmp/dockerbuild-example_js-T1uNwA/Dockerfile'
Sending build context to Docker daemon  37.38kB

Step 1/6 : FROM node:19-bullseye-slim
19-bullseye-slim: Pulling from library/node
f03b40093957: Pulling fs layer
0bfad7312c25: Pulling fs layer
56db04c463e9: Pulling fs layer
477c7ebfb850: Pulling fs layer
8bb4aa3e51be: Pulling fs layer
477c7ebfb850: Waiting
8bb4aa3e51be: Waiting
0bfad7312c25: Verifying Checksum
0bfad7312c25: Download complete
477c7ebfb850: Verifying Checksum
477c7ebfb850: Download complete
f03b40093957: Verifying Checksum
f03b40093957: Download complete
56db04c463e9: Verifying Checksum
56db04c463e9: Download complete
8bb4aa3e51be: Verifying Checksum
8bb4aa3e51be: Download complete
f03b40093957: Pull complete
0bfad7312c25: Pull complete
56db04c463e9: Pull complete
477c7ebfb850: Pull complete
8bb4aa3e51be: Pull complete
Digest: sha256:f58f1fcf5c9ff9e3752993edb4ed6dbd35697124c85a43f3b97aa054500b0534
Status: Downloaded newer image for node:19-bullseye-slim
 ---> adbc02574b52
Step 2/6 : ENTRYPOINT []
 ---> Running in 69399858693c
Removing intermediate container 69399858693c
 ---> 97699dc375a6
Step 3/6 : RUN :
 ---> Running in 84e9bc4152bf
Removing intermediate container 84e9bc4152bf
 ---> 300c79737035
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_js"
 ---> Running in 2280d25a5161
Removing intermediate container 2280d25a5161
 ---> 8c3facc0e723
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:34:10Z"
 ---> Running in 6893d9a30cbe
Removing intermediate container 6893d9a30cbe
 ---> 927647dc42bd
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 14179283d387
Removing intermediate container 14179283d387
 ---> 11f9bda8d23f
Successfully built 11f9bda8d23f
Successfully tagged example_js:test
====================================================================
+/tmp/viash_test_example_js8472287997916680870/test_test/test_executable
>>> Create input test file
>>> Run executable
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory
viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_python5347845775950447368'
====================================================================
+/tmp/viash_test_example_python5347845775950447368/build_executable/example_python ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_python:test' with Dockerfile
[info] Running 'docker build -t example_python:test /tmp/viash_test_example_python5347845775950447368/build_executable -f /tmp/viash_test_example_python5347845775950447368/build_executable/tmp/dockerbuild-example_python-VLQv2T/Dockerfile'
Sending build context to Docker daemon  37.38kB

Step 1/6 : FROM python:3.10-slim
3.10-slim: Pulling from library/python
f03b40093957: Already exists
05c2151a829c: Pulling fs layer
94970648c551: Pulling fs layer
cf2e0f30894f: Pulling fs layer
661be8ca6397: Pulling fs layer
661be8ca6397: Waiting
cf2e0f30894f: Verifying Checksum
cf2e0f30894f: Download complete
05c2151a829c: Verifying Checksum
05c2151a829c: Download complete
94970648c551: Verifying Checksum
94970648c551: Download complete
661be8ca6397: Verifying Checksum
661be8ca6397: Download complete
05c2151a829c: Pull complete
94970648c551: Pull complete
cf2e0f30894f: Pull complete
661be8ca6397: Pull complete
Digest: sha256:fd86924ba14682eb11a3c244f60a35b5dfe3267cbf26d883fb5c14813ce926f1
Status: Downloaded newer image for python:3.10-slim
 ---> 2167e148c9f0
Step 2/6 : ENTRYPOINT []
 ---> Running in 474547b97d8c
Removing intermediate container 474547b97d8c
 ---> 9334576c01b3
Step 3/6 : RUN :
 ---> Running in 3930d2c407ce
Removing intermediate container 3930d2c407ce
 ---> e699f2e0b608
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_python"
 ---> Running in dacaaa18e682
Removing intermediate container dacaaa18e682
 ---> c487e1af7a56
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:34:26Z"
 ---> Running in 6582f8a57e09
Removing intermediate container 6582f8a57e09
 ---> 4f1db1a61583
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 6968e4e133e1
Removing intermediate container 6968e4e133e1
 ---> f6a244c6c491
Successfully built f6a244c6c491
Successfully tagged example_python:test
====================================================================
+/tmp/viash_test_example_python5347845775950447368/test_test/test_executable
Copying 'foo.txt' to 'bar.txt'.
>>> Create input test file
>>> Run executable
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory
viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_r16840132525502699008'
====================================================================
+/tmp/viash_test_example_r16840132525502699008/build_executable/example_r ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_r:test' with Dockerfile
[info] Running 'docker build -t example_r:test /tmp/viash_test_example_r16840132525502699008/build_executable -f /tmp/viash_test_example_r16840132525502699008/build_executable/tmp/dockerbuild-example_r-hGqxcF/Dockerfile'
Sending build context to Docker daemon  37.89kB

Step 1/6 : FROM eddelbuettel/r2u:22.04
22.04: Pulling from eddelbuettel/r2u
e96e057aae67: Pulling fs layer
be5c01dc0d74: Pulling fs layer
a829daef3697: Pulling fs layer
e96e057aae67: Verifying Checksum
e96e057aae67: Download complete
be5c01dc0d74: Verifying Checksum
be5c01dc0d74: Download complete
a829daef3697: Verifying Checksum
a829daef3697: Download complete
e96e057aae67: Pull complete
be5c01dc0d74: Pull complete
a829daef3697: Pull complete
Digest: sha256:4140b831802b488a4fb6be1e4ec9f85d226b788aacd5b3e9b891abab7fcecbb4
Status: Downloaded newer image for eddelbuettel/r2u:22.04
 ---> f1e8042fc279
Step 2/6 : ENTRYPOINT []
 ---> Running in f4f1b771fd8c
Removing intermediate container f4f1b771fd8c
 ---> 45aa16aa30e0
Step 3/6 : RUN :
 ---> Running in 7dbcab05e663
Removing intermediate container 7dbcab05e663
 ---> 9d558a14c18c
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_r"
 ---> Running in 630b03a147cd
Removing intermediate container 630b03a147cd
 ---> 77295a0d538d
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:34:38Z"
 ---> Running in f6cb580d690a
Removing intermediate container f6cb580d690a
 ---> 0b3b6776d217
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 9cdb5d3df31b
Removing intermediate container 9cdb5d3df31b
 ---> 93af4e4062bf
Successfully built 93af4e4062bf
Successfully tagged example_r:test
====================================================================
+/tmp/viash_test_example_r16840132525502699008/test_test/test_executable
>>> Create input test file
>>> Run executable
Copying 'foo.txt' to 'bar.txt'.
[1] TRUE
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory
viash test config.vsh.yaml
Running tests in temporary directory: '/tmp/viash_test_example_scala1729908959009668936'
====================================================================
+/tmp/viash_test_example_scala1729908959009668936/build_executable/example_scala ---verbosity 6 ---setup cachedbuild
[notice] Building container 'example_scala:test' with Dockerfile
[info] Running 'docker build -t example_scala:test /tmp/viash_test_example_scala1729908959009668936/build_executable -f /tmp/viash_test_example_scala1729908959009668936/build_executable/tmp/dockerbuild-example_scala-B7O1B5/Dockerfile'
Sending build context to Docker daemon  37.38kB

Step 1/6 : FROM sbtscala/scala-sbt:eclipse-temurin-19_36_1.7.2_2.13.10
eclipse-temurin-19_36_1.7.2_2.13.10: Pulling from sbtscala/scala-sbt
301a8b74f71f: Pulling fs layer
c5c735a83dbd: Pulling fs layer
5fb9fa7513e6: Pulling fs layer
2af8e2a543d8: Pulling fs layer
14d68137d870: Pulling fs layer
320659737461: Pulling fs layer
1dea7716181a: Pulling fs layer
c9480a4b593f: Pulling fs layer
812216efaf87: Pulling fs layer
4f4fb700ef54: Pulling fs layer
bb7a0c6ab9c1: Pulling fs layer
2c0021742fe2: Pulling fs layer
c9480a4b593f: Waiting
812216efaf87: Waiting
4f4fb700ef54: Waiting
bb7a0c6ab9c1: Waiting
2c0021742fe2: Waiting
2af8e2a543d8: Waiting
14d68137d870: Waiting
320659737461: Waiting
1dea7716181a: Waiting
c5c735a83dbd: Verifying Checksum
c5c735a83dbd: Download complete
301a8b74f71f: Verifying Checksum
301a8b74f71f: Download complete
2af8e2a543d8: Verifying Checksum
2af8e2a543d8: Download complete
14d68137d870: Verifying Checksum
14d68137d870: Download complete
320659737461: Verifying Checksum
320659737461: Download complete
c9480a4b593f: Verifying Checksum
c9480a4b593f: Download complete
812216efaf87: Verifying Checksum
812216efaf87: Download complete
4f4fb700ef54: Verifying Checksum
4f4fb700ef54: Download complete
1dea7716181a: Verifying Checksum
1dea7716181a: Download complete
2c0021742fe2: Verifying Checksum
2c0021742fe2: Download complete
5fb9fa7513e6: Verifying Checksum
5fb9fa7513e6: Download complete
bb7a0c6ab9c1: Verifying Checksum
bb7a0c6ab9c1: Download complete
301a8b74f71f: Pull complete
c5c735a83dbd: Pull complete
5fb9fa7513e6: Pull complete
2af8e2a543d8: Pull complete
14d68137d870: Pull complete
320659737461: Pull complete
1dea7716181a: Pull complete
c9480a4b593f: Pull complete
812216efaf87: Pull complete
4f4fb700ef54: Pull complete
bb7a0c6ab9c1: Pull complete
2c0021742fe2: Pull complete
Digest: sha256:440234e283754375d5ab6bcb35e2d470f9dabeaaeb639d8c0708fac2d3707e0c
Status: Downloaded newer image for sbtscala/scala-sbt:eclipse-temurin-19_36_1.7.2_2.13.10
 ---> 76808e2ea8df
Step 2/6 : ENTRYPOINT []
 ---> Running in 1dcbc3fb6f7b
Removing intermediate container 1dcbc3fb6f7b
 ---> c21d448b6e40
Step 3/6 : RUN :
 ---> Running in eb218d51010e
Removing intermediate container eb218d51010e
 ---> 8475aa46daed
Step 4/6 : LABEL org.opencontainers.image.description="Companion container for running component example_scala"
 ---> Running in 16d0798785fd
Removing intermediate container 16d0798785fd
 ---> 69c8e98a3389
Step 5/6 : LABEL org.opencontainers.image.created="2023-06-02T11:35:02Z"
 ---> Running in c128d167b1d2
Removing intermediate container c128d167b1d2
 ---> 723a8656955f
Step 6/6 : LABEL org.opencontainers.image.version="test"
 ---> Running in 25c112276660
Removing intermediate container 25c112276660
 ---> 5d9755360378
Successfully built 5d9755360378
Successfully tagged example_scala:test
====================================================================
+/tmp/viash_test_example_scala1729908959009668936/test_test/test_executable
warning: 1 deprecation
warning: 1 deprecation (since 2.13.3)
warning: 2 deprecations in total; re-run with -deprecation for details
>>> Create input test file
>>> Run executable
warning: 1 deprecation; re-run with -deprecation for details
Copying 'foo.txt' to 'bar.txt'.
>>> Check whether output file exists
>>> Check whether input and output file are the same
>>> Test finished successfully
====================================================================
SUCCESS! All 1 out of 1 test scripts succeeded!
Cleaning up temporary directory

When running viash test, Viash will follow the following steps:

  1. Create a temporary directory
  2. Build the component into the main executable
  3. (Re-)build the Docker image for the component
  4. Iterate over all unit test scripts:
  1. Build the unit test into an executable
  2. Run the unit test, passing the main executable as an argument
  1. Return exit code 0 if all of the above steps succeed, otherwise 0

Bonus: unit testing all of the components

If you have multiple Viash components located in a directory called src/, what happens when you run the following?

viash ns test --parallel --src src/