apuntes:testing
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| apuntes:testing [2026/09/27 22:41] – [API Testing con Postman] Santiago Faci | apuntes:testing [2026/09/28 22:10] (current) – [Test de integración] Santiago Faci | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ===== Test unitarios ===== | ===== Test unitarios ===== | ||
| + | Se implementan para testear la unidad mínima de código, que normalmente serán funciones o métodos, de forma totalmente aislada del resto de la aplicación. | ||
| ==== Clases de utilidad ==== | ==== Clases de utilidad ==== | ||
| Line 128: | Line 129: | ||
| ===== Test de integración ===== | ===== Test de integración ===== | ||
| + | |||
| + | En este caso escribimos tests que permitan probar varios componentes juntos para verificar que trabajan bien cuando interactuan entre si. | ||
| * Caso de uso: **Ok (200 OK)** | * Caso de uso: **Ok (200 OK)** | ||
| Line 316: | Line 319: | ||
| </ | </ | ||
| - | Puedes encontrar una colección de ejemplo ya preparada con algunos scripts, lista para ser ejecutada con Newman [[https:// | + | Puedes encontrar una colección de ejemplo ya preparada con algunos scripts, lista para ser ejecutada con Newman [[https:// |
| ===== API testing con Postman automatizado con GitHub Actions ===== | ===== API testing con Postman automatizado con GitHub Actions ===== | ||
| Line 325: | Line 328: | ||
| <code yaml> | <code yaml> | ||
| - | FROM eclipse-temurin:21-jdk-alpine | + | FROM node:22-alpine |
| - | VOLUME | + | WORKDIR |
| - | EXPOSE 8080 | + | COPY package*json ./ |
| - | COPY target/games-0.1.jar app.jar | + | RUN npm ci --only=production |
| - | ENTRYPOINT | + | COPY . . |
| + | EXPOSE 3000 | ||
| + | ENV NODE_ENV=production | ||
| + | CMD ["node", "src/app.js"] | ||
| </ | </ | ||
| Line 337: | Line 343: | ||
| <code yaml> | <code yaml> | ||
| - | name: games | + | version: " |
| + | name: cities | ||
| services: | services: | ||
| - | | + | db: |
| image: mariadb: | image: mariadb: | ||
| - | container_name: | + | container_name: |
| - | restart: always | + | |
| environment: | environment: | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | MYSQL_PORT: 3306 | + | |
| - | | + | |
| - | | + | - ./db:/ |
| - | - "3306:3306" | + | |
| healthcheck: | healthcheck: | ||
| - | test: [ CMD, healthcheck.sh, | + | test: [ CMD, healthcheck.sh, |
| - | interval: | + | interval: |
| - | timeout: | + | timeout: |
| retries: 3 | retries: 3 | ||
| networks: | networks: | ||
| - | - network-games | + | - network1 |
| - | | + | |
| - | image: | + | image: |
| - | container_name: | + | container_name: |
| ports: | ports: | ||
| - " | - " | ||
| depends_on: | depends_on: | ||
| - | | + | db: |
| condition: service_healthy | condition: service_healthy | ||
| - | environment: | ||
| - | SPRING_APPLICATION_JSON: | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | }' | ||
| networks: | networks: | ||
| - | - network-games | + | - network1 |
| + | frontend: | ||
| + | image: cities-fe | ||
| + | container_name: | ||
| + | ports: | ||
| + | - " | ||
| + | networks: | ||
| + | - network1 | ||
| networks: | networks: | ||
| - | | + | |
| - | driver: bridge | + | driver: bridge</ |
| - | </ | + | |
| ==== GitHub action ==== | ==== GitHub action ==== | ||
| Line 399: | Line 399: | ||
| branches: | branches: | ||
| - main | - main | ||
| - | - develop | ||
| jobs: | jobs: | ||
| newman: | newman: | ||
| runs-on: ubuntu-latest | runs-on: ubuntu-latest | ||
| + | | ||
| + | strategy: | ||
| + | matrix: | ||
| + | node-version: | ||
| + | | ||
| steps: | steps: | ||
| - uses: actions/ | - uses: actions/ | ||
| - | - uses: actions/ | + | - uses: actions/ |
| with: | with: | ||
| - | | + | |
| - | java-version: '21' | + | cache: 'npm' |
| - | - run: mvn package | + | - run: npm install |
| - | - run: docker build -t games-api . | + | - run: docker build -t cities-api . |
| - run: docker compose up -d | - run: docker compose up -d | ||
| - run: npm install -g newman | - run: npm install -g newman | ||
| - | - run: newman run games.postman_collection.json -e local.postman_environment.json | + | - run: newman run cities.postman_collection.json -e local.postman_environment.json |
| </ | </ | ||
apuntes/testing.1790548871.txt.gz · Last modified: by Santiago Faci
