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

Any​Test

by timfjord ST3

Run any test from Sublime Text

Details

Installs

  • Total 49
  • Win 23
  • Mac 17
  • Linux 9
Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4
Windows 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 2 1 0 0 0 0 0 0
Mac 0 0 0 1 0 0 0 0 0 1 1 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 0 0 0 0 0 1 0
Linux 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 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 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. 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 Cucumber, M, Minitest, Rails, RSpec, Test Bench cucumber, m ,minitest, rails, rspec, test_bench
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

The main command that the package exposes is any_test_run. It supports 4 scopes:

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

The package tries to detect a test framework based on the current file. When the framework is detected the package generates a command and runs it using the selected runner.
When the edit flag is passed to true then the command can be edited before running.
And finally, if the select flag is passed to true then the auto-detection feature is bypassed and the quick panel with all available test frameworks is shown allowing to select a test framework manually.

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 through 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 can 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 used 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 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 the test frameworks that vim-test supports)
  • Run tests from the Side Bar (including testing folders)
  • Show history
  • 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 to the authors and maintainers of this awesome Vim plugin.