Leste is a powerful and user-friendly Lua testing framework heavily inspired by PestPHP and pytest, aiming to simplify and streamline your testing process.
Just like a compass guides you in the right direction, Leste serves as a guiding tool for your tests, ensuring that you stay on the right path to successful testing practices.
The name Leste cleverly merges Lua (L) and teste (Portuguese for test), embodying the playful essence of its creation. Additionally, the word "leste" in Portuguese carries the meaning of "east". This serving as a subtle homage to Lua's Brazilian roots.
Leste can provide visually appealing error reports to streamline your workflow.
Leste offers the following features:
- Assertion Tracking: Leste tracks the total number of assertions made during tests.
- Verbose Output: Choose whether to display the output of the print function inside tests.
- Exit on First Failure: Option to stop running tests after the first failure.
- Test Case Organization: Easily organize test cases with beforeAll, afterAll, beforeEach, and afterEach hooks.
- CLI Interface: Provides a CLI interface for running tests from the command line.
- Flexible Test Case Definition: Define test cases using the
it
function, specifying a description and test function. - Initialization and Cleanup: Initializes the testing framework and cleans up after test execution.
- Detailed Test Reports: Generates detailed test reports including test outcomes, execution time, assertions, and errors.
- Configurable Output: Customize the output format based on verbosity settings.
- Integration with Lua Modules: Seamlessly integrate Leste with Lua modules for testing Lua code.
With Leste, you can streamline your testing process and ensure the reliability of your Lua applications.
You can install Leste using luarocks or cloning this repository, choose the best option that fits you.
Leste is conveniently available through LuaRocks, the Lua package manager. If you already have LuaRocks installed, you can easily install Leste with the following command:
luarocks install leste
This command will automatically download Leste from the LuaRocks repository and generate the leste
script for you. This script enables you to run Leste directly from your command line.
To ensure you can execute Leste from any directory in your terminal, you need to add the LuaRocks bin directory to your system's PATH environment variable. This PATH variable defines the locations your system searches for executable programs.
By default, LuaRocks installs command-line scripts like leste
in a specific directory depending on your installation type:
- System-wide Installation:
/usr/local/bin
- Per-user Installation:
~/.luarocks/bin
(on Unix-like systems)%APPDATA%/luarocks/bin
(on Windows)
-
Clone the repository from GitHub:
git clone https://github.com/AdaiasMagdiel/Leste.git
-
Navigate into the Leste directory:
cd Leste
-
Create a script named
leste
(orleste.bat
for Windows) pointing to theleste/main.lua
file:- For Unix-like systems (Linux, macOS):
#!/bin/bash lua path/to/leste/main.lua $*
- For Windows:
@echo off lua path\to\leste\main.lua %*
- For Unix-like systems (Linux, macOS):
-
Ensure the script is added to your system's PATH so it can be executed from anywhere.
Leste provide a CLI interface for running tests using the testing framework.
leste [options] [file/folder...]
file
: File (or files) with tests to run.folder
: Folder (or folders) to find tests, default is./tests
.
-d, --disable-color
: Disable color for the output, print raw text. Default isfalse
.-h, --help
: Show the usage message and exit.-v, --verbose
: Display output of print function inside tests. Default isfalse
.-x, --exitfirst
: Exit on the first failure. Default isfalse
.
Run tests located in the default ./tests
folder with verbose output:
leste -v
Run tests located in a specific folder:
leste my_tests_folder
Stop the tests after the first failure:
leste -x
To disable colors in the output, use the -d
or --disable-color
flags.
leste -d
First, create a folder named tests
in your project directory. This folder will contain all your test files.
mkdir tests
Inside the tests
folder, create a Lua file for each set of tests you want to write. Ensure that each test file has a filename prefix of "test" so that Leste can discover and execute them. For example, testExample.lua
.
In each test file, you can define multiple test cases using the Leste.it
function. Each test case consists of a description and a function containing the test assertions.
Here's an example of a valid test file (testExample.lua
):
local Leste = require("leste.leste")
-- Test case 1: A basic example
Leste.it("Remember to write an interesting and well-explained description about the test.", function()
assert(true)
end)
-- Test case 2: Using print statements for debugging
Leste.it("You can add print statements if you need to debug, but remember to use the -v flag.", function()
print("This message will appear in the test standard output.")
assert(true)
end)
Tip
Utilizing Lua's assert
function is an effective method for asserting your tests. For more detailed output, consider utilizing the leste.assertions
module. This module offers a range of assert functions that are adept at handling errors more efficiently.
To execute the tests, use the Leste CLI interface. Navigate to your project directory in the terminal and run the following command:
leste -v
This command will automatically run all the test files (test*
) located in the tests
folder. You can also specify a specific folder to run tests from if needed.
Try to run the code without the verbose flag to observe how the print function is silenced.
leste
After running the tests, you will see the test results displayed in the terminal, including passed and failed tests, execution time, and any assertions errors, general errors or debug output.
PASS Remember to write an interesting and well-explained description about the test.
File: testExample.lua
Time: 0.00s
Asserts: .
PASS You can add print statements if you need to debug, but remember to use the -v flag.
File: testExample.lua
Time: 0.00s
Asserts: .
STDOUT:
This message will appear in the test standard output.
✓ All tests passed successfully
Tests: 2 tests 2 passed 0 failed (2 assertions)
Duration: 0.00s
Contributions are welcome Please feel free to submit pull requests or open issues for any bugs or feature requests.
You can start selecting a task from the list in the TODO.md file.
This project is licensed under the MIT License. See the LICENSE file for details.