Skip to content

Commit

Permalink
Merge pull request #42 from Arquisoft/feture/41_gatling_tests
Browse files Browse the repository at this point in the history
Feture/41 gatling tests -- Issue #41
  • Loading branch information
AlvaroGlezC authored Jun 6, 2024
2 parents 37a3ecc + b9d81e5 commit 9b5df7f
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 3 deletions.
Binary file not shown.
Binary file added docs/images/08_api_jacoco_tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_category_gatling_test_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_category_gatling_test_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_category_gatling_test_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_cypress-tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_cypress_test_running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_cypress_tool_tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_java_tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_jest_unit_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_question_gatling_test_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_question_gatling_test_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_question_gatling_test_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_user_gatling_test_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_user_gatling_test_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/08_user_gatling_test_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions docs/src/08_concepts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,33 @@ To test API code, Postman was used during the whole development of the work, to

==== Unit tests
Unit testing was carried out on both the backend and frontend using different technologies to test all the necessary components or modules.
The use of Mock for the backend and the use of jest for the frontend.

The backend has been tested with Jacoco and Java unit tests with Mockito:
image:08_api_jacoco_tests.png["Jacoco tests"]
image:08_java_tests.png["Unit tests"]

The frontend has used Jest for its unit tests:
image:08_jest_unit_test.png["Jest tests"]

==== Integration tests
The integration tests were carried out in test containers with a test database built in these test containers for the adapter layer. It does not make sense to do integration tests on another layer.
The integration tests were carried out in test containers with a test database built in these test containers for the adapter layer. It does not make sense to do integration tests on another layer. This tests was launcher with Jacoco anda java unit test too.

==== e2e tests
For the e2e tests as well as the unit tests and in order to test the application to the maximum, they were carried out both in the frontend with cypress and in the backend with test container again.

E2E cypress tests:
image:08_cypress-tool.png["Cypress tool"]
image:08_cypress_tool_tests.png["Cypress tool tests"]
image:08_cypress_test_running.png["Cypress test running"]

==== load tests
For the load tests, the Gatling tool has been used to measure and monitor the application's times in different scenarios:
image:08_category_gatling_test_01.png["Category gatling 01"]
image:08_category_gatling_test_02.png["Category gatling 02"]
image:08_category_gatling_test_03.png["Category gatling 03"]
image:08_question_gatling_test_01.png["Question gatling 01"]
image:08_question_gatling_test_02.png["Question gatling 02"]
image:08_question_gatling_test_03.png["Question gatling 03"]
image:08_user_gatling_test_01.png["User gatling 01"]
image:08_user_gatling_test_02.png["User gatling 02"]
image:08_user_gatling_test_03.png["User gatling 03"]
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ void generate_wikidata_question() {

questionAdapter.generatedQuestions();
List<Question> questionsAfterGenerate = questionAdapter.findAll();
assertEquals(219, IterableUtil.sizeOf(questionsAfterGenerate));
assertEquals(218, IterableUtil.sizeOf(questionsAfterGenerate));
}
}
5 changes: 5 additions & 0 deletions syg-backend/SYG-rest-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@
<artifactId>SYG-domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package simulations;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class CategoryGatlingTests extends Simulation {

private static final String BASE_URL = "http://localhost:8080";

HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json")
.contentTypeHeader("application/json");

ScenarioBuilder findAllCategories = scenario("Encuentra todas las categorias")
.exec(http("findAllCategories").get("/category").check(status().is(200)));
ScenarioBuilder findCategoryById = scenario("Encuentra una categoria por id")
.exec(http("findCategoryById").get("/category/id?id=1").check(status().is(200)));
{
setUp(findAllCategories.injectOpen(
// Incrementa el número de usuarios rápidamente
incrementUsersPerSec(5).times(12) // Incremento de usuarios por segundo 12 veces (1 minuto)
.eachLevelLasting(5) // Cada nivel dura 5 segundos
.startingFrom(10) // Comienza con 10 usuarios por segundo
), findCategoryById.injectOpen(
incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10))).protocols(httpProtocol)
.maxDuration(300);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package simulations;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class QuestionGatlingTests extends Simulation {

private static final String BASE_URL = "http://localhost:8080";

HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json")
.contentTypeHeader("application/json");

ScenarioBuilder findAllQuestions = scenario("Encuentra todas las preguntas")
.exec(http("findAllQuestions").get("/question").check(status().is(200)));
ScenarioBuilder findQuestionById = scenario("Encuentra una pregunta por su id")
.exec(http("findQuestionById").get("/question/id?id=200").check(status().is(200)));
ScenarioBuilder findQuestionByCategory = scenario("Encuentra una pregunta por su categoria")
.exec(http("findQuestionByCategory").get("/question/category?categoryId=1").check(status().is(200)));
{
setUp(findAllQuestions.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)),
findQuestionById.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)),
findQuestionByCategory
.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)))
.protocols(httpProtocol).maxDuration(300);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package simulations;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class UserGatlingTests extends Simulation {

private static final String BASE_URL = "http://localhost:8080";

HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json")
.contentTypeHeader("application/json");

ScenarioBuilder findUserById = scenario("Encuentra un usuario por su uuid").exec(
http("findUserById").get("/user/userId?id=4366fdc8-b32d-46bc-9df8-2e8ce68f0743").check(status().is(200)));
ScenarioBuilder findUserByName = scenario("Encuentra un usuario por nombre")
.exec(http("findUserByName").get("/user/name/?userName=alvaro").check(status().is(200)));

{
setUp(findUserById.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)),
findUserByName.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)))
.protocols(httpProtocol).maxDuration(300);
}
}
33 changes: 33 additions & 0 deletions syg-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<sonar.coverage.jacoco.xmlReportPaths>SYG-bootstrap/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.exclusions>SYG-bootstrap/**, SYG-domain/src/main/java/syg/domain/model/** </sonar.exclusions>

<gatling.version>3.11.3</gatling.version>
<gatling-maven-plugin.version>4.9.4</gatling-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-jar-plugin.version>3.4.1</maven-jar-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -78,6 +83,12 @@
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -187,6 +198,28 @@
<artifactId>sonar-maven-plugin</artifactId>
<version>3.11.0.3922</version>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
<configuration>
<!-- Enterprise Cloud (https://cloud.gatling.io/) configuration reference: https://gatling.io/docs/gatling/reference/current/extensions/maven_plugin/#working-with-gatling-enterprise-cloud -->
<!-- Enterprise Self-Hosted configuration reference: https://gatling.io/docs/gatling/reference/current/extensions/maven_plugin/#working-with-gatling-enterprise-self-hosted -->
</configuration>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit 9b5df7f

Please sign in to comment.