ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Any​Test

by timfjord ST3

Run any test from Sublime Text

Details

Installs

  • Total 24
  • Win 10
  • Mac 9
  • Linux 5
May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3
Windows 0 0 1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 2
Mac 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1
Linux 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 2 0 0 0 1 0

Readme

Source
raw.​githubusercontent.​com

Stand With Ukraine

AnyTest Lint Test

Run any test from Sublime Text

A Sublime Text ¾ package whose main idea is to automatically detect a test framework for the given file and run it.
Basically it is a Sublime Text interpretation of the awesome vim-test plugin.

Currently the following test frameworks are supported (more test frameworks are coming soon):

Language Test framework Identifiers
Elixir ESpec, ExUnit espec, exunit
JavaScript Jest jest
Python PyTest, PyUnit pytest, pyunit
Ruby Minitest, RSpec minitest, rspec
Rust Cargo cargotest

Feel free to open an issue with a test framework request as those test frameworks will be added first.

Installation

  1. Install the Sublime Text Package Control package if you don't have it already.
  2. Open the command palette and start typing Package Control: Install Package.
  3. Enter AnyTest.

Usage

There are 4 main commands that the package exposes:

  • AnyTest: Test suite: runs the whole test suite (based on the current file)
  • AnyTest: Test file: runs all tests in the current file
  • AnyTest: Test nearest: runs the test nearest to the current line(cursor)
  • AnyTest: Run last: runs the last test

Any of the commands above supports the edit flag that allows editing the command before running it.

The package comes with polyfills for test frameworks that don't have built-in support for running tests for the current line.
All the polyfills have been borrowed from the vim-test plugin and adapted for Sublime Text.

All the package commands can be found in Default.sublime-commands

By default the package doesn't define any key bindings, run Preferences: AnyTest Key Bindings to define your own bindings.

Configuration

The package can be configured either globally or at the project level. Settings defined at the project level override settings defined globally.

To configure the package at the project level all settings must be added under the AnyTest namespace:

{
    "folders": [
        {
            "path": ".",
        }
    ],
    "settings": {
        "AnyTest": {
            "test_frameworks": {
                "python": "pyunit"
            },
            "python.pyunit.runner": "unittesting"
        }
    }
}

The package provides schemas for its settings so it is recommended to install LSP-json to have settings autocomplete.

To see all available settings please check AnyTest.sublime-settings

By default the package iterates thought all available test frameworks to detect the one to use. This can be changed with the test_frameworks setting:

"test_frameworks": {
  "python": "pyunit"
}

or

"test_frameworks": {
  "python": ["pyunit", "pytest"]
}

this way all other test frameworks will be ignored.

Also, some languages support specifying test framework, for example

"python.test_framework": "pytest"

This won't change the detection process, but if there are multiple candidates the specified one will be used.

Project folders

The package supports multiple project folders. It can be very useful when there is a nested folder that contains a separate project. The package is able to detect this situation and calculates the root path correctly

Runners

The package comes with 3 runners:

  • command
  • terminus
  • console

The default runner is command. It uses the built-in Sublime exec command(the command can be configured) to run the test command.
The command runner is a bit limited so it is recommended to install Terminus package and use the terminus runner instead.

The console runner is mostly user for testing/debugging as its main purpose is to output the test command and metadata to the console.

Runners can be activated globally, per language or per framework:

"runner": "terminus",
"python.runner": "command",
"python.pyunit.runner": "unittesting"

Please consult with AnyTest.sublime-settings to check all available settings.

There is also the unittesting runner and it should be used to test sublime packages with UnitTesting.
Unfortunately, due to UnitTesting limitations there is no way to run tests for the current line.
Using unittesting only makes sense with PyUnit test framework, so it is usually activated as:

"python.pyunit.runner": "unittesting"

Roadmap

  • Add more test frameworks (the end goal is to at least support all test frameworks that vim-test supports)
  • Allow to explicitly select a test framework for the given file/project
  • Run tests from the Side Bar (including testing folders)
  • Potentially integrate the package with Sublime Debugger

Contribution

The easiest way to add a new test framework is to find it in the vim-test repository and try to adapt it.
It is also required to cover the test frameworks with tests. Tests and fixtures can be also found in the vim-test repository

The package uses black, flake8 and isort for linting.

Credits

AnyTest is heavily inspired by the vim-test plugin so all credits go the authors and maintainers of this awesome Vim plugin.