Browse Source

Docs for Unit Tests and Functional Tests per microservice and Global.

pull/675/head
Cesar De la Torre 6 years ago
parent
commit
97dcf49705
12 changed files with 129 additions and 40 deletions
  1. BIN
      img/unitandfunctests/unittestsview.PNG
  2. +0
    -40
      readme/running-unit-func-tests.md
  3. BIN
      test/img/compose-up-powershell-infrastructure-containers.PNG
  4. BIN
      test/img/functionaltests-catalog-running.PNG
  5. +0
    -0
      test/img/functionaltestsview.PNG
  6. BIN
      test/img/global-application-functional-tests-running.PNG
  7. +0
    -0
      test/img/integrationtestsview.PNG
  8. +0
    -0
      test/img/orderingservicetests.PNG
  9. BIN
      test/img/services-functional-tests-folder.PNG
  10. BIN
      test/img/unittestsrunning.PNG
  11. BIN
      test/img/unittestsview.PNG
  12. +129
    -0
      test/readme.md

BIN
img/unitandfunctests/unittestsview.PNG View File

Before After
Width: 574  |  Height: 369  |  Size: 10 KiB

+ 0
- 40
readme/running-unit-func-tests.md View File

@ -1,40 +0,0 @@
# Running UnitTests, Functional and Laod Tests on eshopOnContainers
## Unit and Functional tests for each microservice
En cada uno de los diferentes micro-servicios creados hay disponibles el conjunto de tests creados para validar su funcionamiento. Con el fin de mantener lo máximo posible la autonomía de cada micro-servicio los diferentes proyectos de tests están físicamente juntos con el resto de código. Así, por ejemplo, si desplegamos en nuestro explorador de soluciones el codigo del servicio de *Ordering* podrá ver los proyectos de *Ordering.FunctionalTests* y *Ordering.UnitTests*.
<p>
<img src="../img/unitandfunctests/orderingservicetests.PNG">
<p>
Para ejecutar los tests unitarios de los diferentes micro-servicios solamente tendremos que seleccionarlos con nuestro *TestView*, o su herramienta preferida, y ejecutarlos. Estos tests no tienen ninguna dependencia y por lo tanto no se necesita nada especial para que los mismos funcionen.
Al contrario, los tests funcionales si tienen dependencias con ciertos elementos de la infraestructura como por ejemplo, la base de datos de Sql Server, el sistema de colas etc.
<p>
<img src="../img/unitandfunctests/functionaltestsview.PNG">
<p>
Por ello, para correr estos tests es necesario tener disponible ciertos elementos de infraestructura. Con el fin de facilitar esta construcción en la carpeta de tests se dispone de un compose que nos permitirá crear estos elementos.
> docker-compose -f .\docker-compose-tests.yml -f .\docker-compose-tests.override.yml up
Cada proyecto de test funcionales usa un TestServer configurado con la infraestructura levantada en el compose anterior que nos permitirá correr sin ningun problema los diferentes tests.
> Puede obtener más información sobre *TestServer* en [este enlace](https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.1).
## Integration Tests
Hasta aquí hemos hablado sobre como cada micro-servicio contiene los tests, unitarios y funcionales, que le ocupan, no obstante también son necesarios diferentes tests de integración para verificar el trabajo entre los diferentes elementos. Estos proyectos de pruebas están situados en un lugar común, la carpeta tests y contiene las diferentes pruebas de integración del sistema.
<p>
<img src="../img/unitandfunctests/integrationtestsview.PNG">
<p>
Para poder ejecutarlos, al igual que antes es necesario disponer de la infraestructura necesaria con lo que podemos utilizar el *compose* mencionado anteriormente.
## LoadTests project
El trabajo con los tests de carga está descrito en [este fichero de documentación](../test/ServicesTests/LoadTest/readme.md) que puede leer.

BIN
test/img/compose-up-powershell-infrastructure-containers.PNG View File

Before After
Width: 1149  |  Height: 271  |  Size: 150 KiB

BIN
test/img/functionaltests-catalog-running.PNG View File

Before After
Width: 570  |  Height: 465  |  Size: 214 KiB

img/unitandfunctests/functionaltestsview.PNG → test/img/functionaltestsview.PNG View File


BIN
test/img/global-application-functional-tests-running.PNG View File

Before After
Width: 493  |  Height: 341  |  Size: 74 KiB

img/unitandfunctests/integrationtestsview.PNG → test/img/integrationtestsview.PNG View File


img/unitandfunctests/orderingservicetests.PNG → test/img/orderingservicetests.PNG View File


BIN
test/img/services-functional-tests-folder.PNG View File

Before After
Width: 718  |  Height: 222  |  Size: 40 KiB

BIN
test/img/unittestsrunning.PNG View File

Before After
Width: 388  |  Height: 251  |  Size: 62 KiB

BIN
test/img/unittestsview.PNG View File

Before After
Width: 375  |  Height: 191  |  Size: 12 KiB

+ 129
- 0
test/readme.md View File

@ -0,0 +1,129 @@
# Running Tests for eShopOnContainers
The tests in eShopOnContainers are structured in the following structure, per type:
- Tests per microservice
- Unit Tests
- Functional/Integration Tests
- Global application tests
- Microservices Functional/Integration Tests across the whole application
# Unit and Functional tests per microservice
Within each microservice's folder there are multiple tests (Unit Tests and Functional Tests) available to validate its behaviour.
The test projects are positioned within each microservice's physical folder because that helps on the goal of maitanining maximum development autonomy per microservice. Doing it this way and in a more advance scenario, you could even move each microservice to a different GitHub repo per microservice, along with its test projects.
For instance, this is the way you see the project folders for the *Ordering* microservice, where you also have the *Ordering.FunctionalTests* y *Ordering.UnitTests* within that folder structure.
<p>
<img src="img/orderingservicetests.PNG">
<p>
## Running Unit Tests for specific microservices
In order to run the Unit Tests for any microservice, you just need to select the tests with [*Test Explorer* in Visual Studio](https://docs.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer) (or use your preferred tool) and run the tests.
For instance, you can filter and see just the Unit Test projects by typing *"UnitTest"* in the filter edit box within **Test Explorer**:
<p>
<img src="img/unittestsview.PNG">
<p>
Then you can run all or selected tests, like in the following image:
<p>
<img src="img/unittestsrunning.PNG">
<p>
These Unit Tests have no any dependency with any external infrastructure or any other microservice and that's why you don't need to spin-up additional infrastructure (Database server or additional containers).
## Running Functional/Integration Tests for specific microservices
In this case, the Functional Tests do have dependencies with additional infrastructure. For instance, they might have dependencies with the microservices's database in the SQL Server container, the messaging broker (RabbitMQ container), etc.
Therefore, in order to run the Functional Tests you first need to have the needed inrastructure, in this case to spin-up the infrastructure containers.
In order to facilitate how you can have the infrastructure containers up and running, you have certain docker-compose files you can use with `docker-compose up`. These files are available here:
https://github.com/dotnet-architecture/eShopOnContainers/tree/feature/orgtestprojects/test
If you edit the docker-compose-tests.yml you can see that it just have info about the infrastructure containers to spin up:
```
docker-compose-tests.yml
version: '3'
services:
redis.data:
image: redis:alpine
rabbitmq:
image: rabbitmq:3-management-alpine
sql.data:
image: microsoft/mssql-server-linux:2017-latest
nosql.data:
image: mongo
```
Here is how you start the infrastructure containers with "docker-compose up" in PowerShell or any Command-Line window:
> docker-compose -f .\docker-compose-tests.yml -f .\docker-compose-tests.override.yml up
<p>
<img src="img/compose-up-powershell-infrastructure-containers.PNG">
<p>
Each Functional Test project uses a [TestServer](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.testhost.testserver?view=aspnetcore-2.1) configured with the required infrastructure which should be available thanks to the previous "docker-compose up", so the Functional Tests can be run.
> For more info about **TestServer** and *Functional Tests* and *Integration Tests*, see the article [Integration tests in ASP.NET Core](https://docs.microsoft.com/aspnet/core/test/integration-tests?view=aspnetcore-2.1).
In order to filter and see the Functional Tests to run, type *"Functional"* in **Test Explorer**.
<p>
<img src="img/functionaltestsview.PNG">
<p>
You can, for instance, run the Functional Tests for the Catalog Microservice, which, under the covers, are accessing to the SQL Server container that should be running in Docker:
<p>
<img src="img/functionaltests-catalog-running.PNG">
<p>
# Running Services Integration Tests (Tests across the whole application)
So far, we've been focusing on isolated Unit Tests or Functional Tests that were related to single/isolated microservices, although taking into account the infrastructure for the functional tests per microservice.
However, in a microservice-based application you also need how the multiple microservices interact with the whole application. For instance, you might raise an envent from one microservice by publishing it on the Event Bus (based on RabbitMQ) and test/validate that you received that same event into another microservice because it was subscribed to it.
These global Functional/Integration tests for the services need to be placed in a common place instead within specific microservice's folders, as it needs to deal with multiple microservices.
That common place is the **"test/ServiceTests/FunctionalTests"** folder and it has those multiple integration tests for the whole application.
<p>
<img src="img/services-functional-tests-folder.PNG">
<p>
In order to run these application services tests, you can filter, like in the following image.
<p>
<img src="img/integrationtestsview.PNG">
<p>
Then, making sure that you have the infrastructure containers up and running (thanks to the previous `docker-compose up` command, already explained), select and run the desired global application functional tests, as in the following image:
<p>
<img src="img/global-application-functional-tests-running.PNG">
<p>
## Load Testing
Load Testing for eShopOnContainers is described in [this document](ServicesTests/LoadTest/readme.md)

Loading…
Cancel
Save