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:
npm install -g @bugster/cli
-
Authenticate with Bugster
Run the following command and follow the prompts:
bugster auth login
-
Configure Your Project
In your project root, create a
bugster.config.js
file:module.exports = { apiKey: 'YOUR_BUGSTER_API_KEY', apiKey: 'YOUR_API_KEY', testDir: './tests', browsers: ['chrome', 'firefox'], baseUrl: 'http://localhost:3000' };
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:
bugster tests download
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:
bugster tests run
Running Specific Tests
To run a subset of tests:
-
By test file:
bugster tests run ./tests/login.test.js
-
By tag:
bugster tests run --tag smoke
-
By test suite:
bugster tests run --suite "Critical Path"
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 inbugster tests run --browser chrome,firefox
-
--headless
: Run tests in headless modebugster tests run --headless
-
--parallel
: Set number of parallel test runsbugster tests run --parallel 4
Configuration File Options
Edit your bugster.config.js
to set default options:
module.exports = {
// ... other options
runConfig: {
headless: true,
parallel: 2,
retries: 2,
timeout: 30000 // milliseconds
}
};
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:bugster tests run --report
-
Open the generated HTML report in your browser:
open bugster-report.html
Debugging Failed Tests
When a test fails locally:
-
Re-run the specific failed test with increased verbosity:
bugster tests run ./tests/failed-test.js --debug
-
Use the
--stop-on-failure
flag to pause execution at the point of failure:bugster tests run --stop-on-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:
bugster tests run --watch
-
Pre-commit Hooks: Set up a pre-commit hook to run tests before allowing commits:
npx husky add .husky/pre-commit "bugster tests run --tag quick"
-
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.