Skip to content

Testing solutions written in different languages

Sergey edited this page May 24, 2023 · 2 revisions

Table of contents

  1. Python
  2. Other languages
    1. Initial setup
    2. Go
      1. Project structure
      2. File templates
    3. JavaScript
      1. Project structure
      2. File templates
    4. Bash
      1. Project structure
      2. File templates

The hs-test-python library supports testing solutions written in different languages. Let's discuss how to create them.

Python

The main language for checking solutions with the hs-test-python library is Python.

In this case, the project structure and initial templates are described in file templates section.

Other languages

Initial setup

When creating a project with a solution intended to be not in Python, you still need to create the project in JetBrains Academy using Type: Hyperskill Python. The contents of Description will not be shown anywhere, so don't worry about that.

The reason you have to choose Type: Hyperskill Python is that in this case JetBrains Academy plugin upon clicking Check will run Python tests locally (because it knows that it totally can check Python projects locally). The hs-test-python however, will see no files with extension .py and will run other files based on the file extension.

After creating a JetBrains Academy project, you need to create requirements.txt file templates and following sections. This will ensure that Python tests will run correctly.

Go

Go project structure

In case of Go, you can just place .go files right in the root of the stage. It will be the initial template for the project.

After creating tests and Go solution, you can test it using the button Check in the Task section of JetBrains Academy plugin. Additionally, you can open the tests and click on the green triangle to run tests explicitly without JetBrains Academy plugin.

Note: To run tests properly, you need the command go to be executable in the command line (in your path). hs-test-python will run exactly this command to run the user's solution.

After that, you should end up with the following file structure:

Go file templates

You can create the initial file with the following content:

package main

func main() {
    // write your code here
}

JavaScript

JavaScript project structure

In case of JavaScript, you can just place one or multiple .js files right in the root of the stage. It will be the initial template for the project.

You should create dependencies file named package.json in the root of the project with the following content:

{
  "devDependencies": {
    "sync-input": "https://github.com/hyperskill/sync-input/archive/release.tar.gz"
  }
}

The reason for this dependency is that NodeJS doesn't have input() command like Python or System.in like Java, so this dependency adds support for such functionality. There's separate repository for this dependency, it's tiny dependency.

You can add additional dependencies here if you want the users to be able to use them in their solution, just remember that with additional dependencies users will not be able to solve the project in a web-interface on Hyperskill since only sync-input is installed there.

After creating this file, IDEA will suggest you to run npm install, you should do that.

After creating tests and JavaScrint solution, you can test it using the button Check in the Task section of JetBrains Academy plugin. Additionally, you can open the tests and click on the green triangle to run tests explicitly without JetBrains Academy plugin.

Note: To run tests properly, you need the command node to be executable in the command line (in your path). hs-test-python will run exactly this command to run the user's solution.

After all of that, you should end up with the following file structure:

JavaScript file templates

You can create the initial file with the following content. Since sync-input is an additional dependency, you can leave the comment explaining what it's doing and how to use it. You can remove the line // You will need this in the following stages if the user is required to input some data already in the first stage.

// Use "input()" to input a line from the user
// Use "input(str)" to print some text before requesting input
// You will need this in the following stages
const input = require('sync-input')

console.log("Hello, World!")

Bash

Bash project structure

In case of Bash, you don't need src folder - you can just place .sh files right in the root of the stage. It will be the initial template for the project.

After creating tests and Bash solution, you can test it using the button Check in the Task section of JetBrains Academy plugin. Additionally, you can open the tests and click on the green triangle to run tests explicitly without JetBrains Academy plugin.

Note: To run tests properly, you need the command bash to be executable in the command line (in your path). hs-test-python will run exactly this command to run the user's solution. If you're on Windows, you need WSL2 to be installed. However, users that will try to solve the project don't need to meet such requirements because when completing such Bash project on Hyperskill, JetBrains Academy will send the solution to be checked on Hyperskill side. But for development, you need to have bash locally.

After that, you should end up with the following file structure:

Bash file templates

You can create the initial file with the following content:

echo Hello, World!