Gatling Maven Project Setup Demo | Command Line Runs
HTML-код
- Опубликовано: 28 сен 2024
- All Free Tutorials 🟢 AutomationStep...
How to setup maven project (java & scala)
How to run maven commands
How to run specific test simulation
How to run multiple test simulation
Gatling Maven Project Setup
Step 1 - Check Prerequisites
java -version
mvn -version
Step 2 - On IntelliJ IDE Go to File > New > Project from Version Control
Paste the repository URL
Java - github.com/gat...
Scala - github.com/gat...
Step 3 - Select local folder, Click Clone
To view all dependencies goto File > View > Tool Windows > Maven
For Scala project:
scala -version (not needed if scala plugin added on IntelliJ IDE)
check scala plugin is added in the IDE (File - Settings - Plugins)
can add scala in Project Libraries (File - Project Structure - Global Libraries - Scala)
In case the scala and resources folder not already marked
Rt click on scala folder > Mark Directory as > Test Sources root
Rt click on resources folder > Mark Directory as > Test Resources root
Step 4 - Open command line and goto the location of project folder
Try these commands:
mvn clean gatling:help
mvn clean gatling:verify
mvn clean gatling:recorder
mvn clean gatling:test
mvn clean gatling:test -Dgatling.simulationClass=com….Sim1
Can try running the Engine and Recorder classes manually and check
To run Multiple Simulations mvn clean gatling:test
Add in pom.xml
<configuration>
<runMultipleSimulations>true</runMultipleSimulations>
</configuration>
Ref:
gatling.io/202...
gatling.io/doc...
▬▬▬▬▬▬▬
Every Like & Subscription gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can
If my work has helped you, consider helping any animal near you, in any way you can
Never Stop Learning
Raghav Pal
---
How to run Gatling from command line
How to run multiple simulations in Gatling from commandline
Gatling maven project with commands
Hi, thank you for sharing informative video on Gatling.
I have started exploring Gatling where i am trying to do research on externalizing configuration like API base uri, headers, request payload ...etc for simulation class...
Can you share your thoughts on how to do it ??
Pratik
Gatling provides several ways to externalize configuration. Here are a few options:
* Properties files: You can store configuration values in a properties file (e.g., `application.properties`) and load them in your simulation.
* Environment variables: You can set environment variables and access them in your simulation using the `System.getProperty()` method.
* Configuration classes: You can create a configuration class that holds the values and inject it into your simulation.
For this example, let's use the properties file approach.
Step 1: Choose a configuration approach
Gatling provides several ways to externalize configuration. Here are a few options:
* Properties files: You can store configuration values in a properties file (e.g., `application.properties`) and load them in your simulation.
* Environment variables: You can set environment variables and access them in your simulation using the `System.getProperty()` method.
* Configuration classes: You can create a configuration class that holds the values and inject it into your simulation.
For this example, let's use the properties file approach.
Step 2: Create a properties file
Create a file named `application.properties` in the root of your project (or in a location that's accessible by your simulation). Add the configuration values you want to externalize, such as:
```properties
api.base.uri=example.com/api
api.headers.Content-Type=application/json
api.request.payload={"key": "value"}
```
Step 3: Load the properties file in your simulation
In your simulation class, add the following code to load the properties file:
```scala
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class MySimulation extends Simulation {
val props = new Properties()
props.load(new FileInputStream("application.properties"))
val apiBaseUri = props.getProperty("api.base.uri")
val apiHeaders = Map("Content-Type" -> props.getProperty("api.headers.Content-Type"))
val apiRequestPayload = props.getProperty("api.request.payload")
// Use the externalized configuration values in your scenario
val scn = scenario("My Scenario")
.exec(http("Get API")
.get(apiBaseUri + "/ endpoint")
.headers(apiHeaders)
.body(StringBody(apiRequestPayload))
)
}
```
In this example, we load the `application.properties` file using the `Properties` class and retrieve the values using the `getProperty()` method. We then use these values to configure our HTTP request.
Step 5: Run your simulation
Run
-
@@RaghavPal
Thank you so much for the detailed explaination .. this really helped me !!
Hi Raghav.
I have another query...please help me out.
How to do LLM testing.
Sonal
LLM testing stands for Load, Latency, and Memory testing. Let's break down each component:
1. Load Testing:
- Purpose: Load testing evaluates how well a system performs under expected and peak loads.
- Process:
- Identify critical scenarios (e.g., user registration, checkout process).
- Create test scripts that simulate user interactions (using tools like JMeter, Gatling, or custom scripts).
- Gradually increase the load (number of concurrent users or requests) to observe system behavior.
- Monitor response times, resource utilization, and errors.
- Analyze bottlenecks and optimize system components.
2. Latency Testing:
- Purpose: Latency testing assesses the delay between sending a request and receiving a response.
- Process:
- Measure the time taken for various operations (e.g., database queries, API calls, page rendering).
- Use tools like Ping, Traceroute, or specialized latency measurement tools.
- Set acceptable latency thresholds based on user expectations.
- Investigate high latency areas and optimize them.
3. Memory Testing:
- Purpose: Memory testing ensures that an application manages memory efficiently.
- Process:
- Monitor memory usage during different scenarios (e.g., login, data processing).
- Use tools like Valgrind, JConsole, or built-in profilers.
- Check for memory leaks (unreleased memory) and excessive memory consumption.
- Optimize code, release unused resources, and manage memory effectively.
4. Integration with Performance Testing:
- LLM testing often integrates with overall performance testing:
- Performance Testing: Includes load, stress, scalability, and endurance testing.
- LLM Testing: Focuses on specific aspects related to load, latency, and memory.
- Together, they provide a comprehensive view of system performance.
Remember, effective LLM testing requires a combination of tools, monitoring, and analysis. Start by understanding your application's requirements and user expectations, and tailor your testing accordingly.
all the best..
Please share java script in Gatling. How to add the project in maven
I will check on this