Categorygithub.com/kampanosg/lazytest
repositorypackage
0.5.3
Repository: https://github.com/kampanosg/lazytest.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

LazyTest 🥱🧪
LazyTest is a command line tool that helps you view, search and run tests in your project.

the lazytest tui

Features ⭐

Run a test

Run a test suite

Run all tests

Run failed tests

Run passed tests

Search for a test

Resize the panes

Sometimes test names may exceed the size of the pane. Or you may need more space for the output text. Unfortunately, tview, the TUI library that LazyTest uses, does not support horizontal scrolling (and it's probably not going to be implemented any time soon).

As an alternative, LazyTest panes can be resized with the + and - keys.

Installation ⬇️

Go

You can use Go to install LazyTest

go install github.com/kampanosg/lazytest@latest

Download the executable

You can download the executable for your OS by going to the releases page. You can move the executable to your $PATH.

Build from source

[!IMPORTANT] You need Go v1.22 to build the project.

Makefile

You can build the project with make

make

An executable called lazytest will be built. You can move it to your $PATH

Bakery

If you're a Bakery fan (well, thank you!), LazyTest comes with a Bakefile that you can use with bake. You can just run

bake

An executable called lazytest will be built. You can move it to your $PATH

Engines 🏎️

"Engines" are a core concept in LazyTest. It allows the tool to be extensible and work with many languages and test frameworks. LazyTest uses engines to parse the codebase and determine which files contain tests. Engines also provide instructions on how to run a given test.

You can write a new Engine by implementing the following interface:

type LazyEngine interface {
	Load(dir string) (*models.LazyTree, error)
	GetIcon() string
}

The Load function parses the contents of dir and constructs a LazyTree which includes all the tests. The tree is then passed to the TUI that renders it on the terminal

https://github.com/kampanosg/lazytest/blob/c0ce2bfdbc501a91c26662c20bbe154c907dd500/pkg/engines/golang/engine.go#L37-L71

Available Engines

LazyTests comes packed with the following engines:

Usage ⚙️

LazyTest aims to be as intuitive and easy to use as possible. If you're familiar with other terminal applications, LazyTest should (hopefully) feel natural. The table below lists all the available keys and modes.

KeyDescriptionWhere
?Opens the help dialog
j/kNavigate up/downTests Panel
↑/↓Navigate up downTests Panel
Enter/SpaceFold/Unfold a nodeTests Panel
1Focus on the Tests Panel
2Focus on the Output Panel
3Focus on the History Panel
4Focus on the Timings Panel
rRun a Test or Test SuiteTests Panel
aRun all TestsTests Panel
pRun Passed Tests (from previous run)Tests Panel
fRun Failed Tests (from previous run)Tests Panel
/Enter Search ModeTests Panel
EscExit Search ModeSearch Panel
EnterGo to Search ResultsSearch Panel
CClear Search ResultsTests Panel
+Increase the Tests Panel size
-Decrease the Tests Panel size
0Reset the layout
yCopy the test name/test suite pathTests Panel
YCopy the (current) outputTests Panel
qQuit the app

Use it with ToggleTerm

ToggleTerm is a popular NeoVim plugin that lets you "persist and toggle multiple terminals during an editing session". It can be used with LazyTest, to avoid context-switching when you have to run your tests.

You can add the following to your NeoVim config:

local Terminal  = require('toggleterm.terminal').Terminal

local lazytest = Terminal:new({
  cmd = "lazytest",
  dir = ".",
  direction = "float",
  float_opts = {
    border = "curved",
  },
  -- function to run on opening the terminal
  on_open = function(term)
    vim.cmd("startinsert!")
    vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", {noremap = true, silent = true})
  end,
  -- function to run on closing the terminal
  on_close = function(term)
    vim.cmd("startinsert!")
  end,
})

function _lazytest_toggle()
  lazytest:toggle()
end

vim.api.nvim_set_keymap("n", "<C-t>", "<cmd>lua _lazytest_toggle()<CR>", {noremap = true, silent = true})

The above binds <C-t> to bring up a new floating terminal and executes the ./lazytest command. You can quit the terminal by pressing q. Make sure you include this config to your init.lua.

[!NOTE] You can view and example of my NeoVim x LazyTest configuration here

Flags

LazyTest supports the following flags that can be passed with the executable

FlagDescriptionExample
dirthe directory to start searching for testslazytest -dir /Code/example/project
exclengines to excludelazytest -excl=rust,zig
versionthe current version of LazyTest

Inspiration & Similar Projects 💬

LazyTest is heavily inspired by the following projects. Go check them out - their work is excellent!

  • LazyGit - A simple terminal UI for git commands
  • NeoTest - A framework for interacting with tests within NeoVim.

Mandatory GIF 🖼️


The average developer when being asked to write tests