Running Tests Locally
Learn how to execute Bugster SDK tests on your local machine for rapid development and debugging
Introduction
Running tests locally is an essential part of the development process, allowing you to quickly validate changes, debug issues, and ensure the quality of your application before pushing to shared environments. This guide will walk you through the process of setting up and running Bugster SDK tests on your local machine.
Prerequisites
Before you begin, ensure you have the following:
- Bugster SDK installed in your project
- Node.js (version 14 or later) installed on your machine
- Access to your project’s test suite in the Bugster dashboard
Setting Up Your Local Environment
-
Install Bugster CLI
Open your terminal and run:
-
Authenticate with Bugster
Run the following command and follow the prompts:
-
Configure Your Project
In your project root, create a
bugster.config.js
file:Replace
YOUR_BUGSTER_API_KEY
andYOUR_API_KEY
with your actual project details.
Downloading Tests
To run tests locally, you first need to download them from the Bugster dashboard:
-
Open your terminal in your project directory.
-
Run the following command:
This will download all the tests associated with your project into the testDir
specified in your config file.
Running All Tests
To run all downloaded tests:
-
Ensure your application is running locally (e.g., on
http://localhost:3000
). -
Open a new terminal window.
-
Run:
Running Specific Tests
To run a subset of tests:
-
By test file:
-
By tag:
-
By test suite:
Configuring Test Runs
You can customize your test runs using command-line options or by editing your bugster.config.js
file.
Command-line Options
-
--browser
: Specify browser(s) to run tests in -
--headless
: Run tests in headless mode -
--parallel
: Set number of parallel test runs
Configuration File Options
Edit your bugster.config.js
to set default options:
Viewing Test Results
After running tests, Bugster CLI will display a summary of the results in your terminal. For a more detailed view:
-
Run tests with the
--report
flag: -
Open the generated HTML report in your browser:
Debugging Failed Tests
When a test fails locally:
-
Re-run the specific failed test with increased verbosity:
-
Use the
--stop-on-failure
flag to pause execution at the point of failure: -
Check the screenshots and video recordings in the
./bugster-results
directory.
Best Practices for Local Test Execution
-
Run Tests Frequently: Execute tests after every significant code change.
-
Use a Consistent Environment: Ensure your local setup mirrors your CI environment as closely as possible.
-
Optimize for Speed: Use parallel execution and headless mode for faster feedback.
-
Manage Test Data: Use Bugster’s data management features to handle test data consistently across environments.
-
Version Control Your Config: Keep your
bugster.config.js
in version control to ensure consistency across the team.
Troubleshooting Common Issues
-
Tests Failing Locally but Passing in CI:
- Check for environment-specific configurations.
- Ensure all dependencies are installed and up-to-date.
-
Slow Test Execution:
- Use headless mode and increase parallelization.
- Review and optimize wait times in your tests.
-
Browser Launch Failures:
- Verify that the specified browsers are installed on your machine.
- Check for conflicting browser sessions or processes.
-
Network-Related Failures:
- Confirm your application is running and accessible at the specified
baseUrl
. - Check your network connection and firewall settings.
- Confirm your application is running and accessible at the specified
Integrating with Local Development Workflow
-
Watch Mode: Use Bugster’s watch mode to automatically run relevant tests as you make changes:
-
Pre-commit Hooks: Set up a pre-commit hook to run tests before allowing commits:
-
IDE Integration: Use Bugster’s IDE plugins for Visual Studio Code or JetBrains IDEs for seamless test execution from your editor.
Next Steps
Now that you’re comfortable running tests locally, you might want to explore:
- Cloud Execution for running tests at scale
- CI/CD Integration to automate your testing pipeline
- Advanced Test Writing to create more robust and efficient tests
If you encounter any issues or have questions about running tests locally, don’t hesitate to contact our support team or visit our community forums.