Files
KarmaTashiCat 84f7ab8006 translation: It would close #2479 and #2481 (#2480)
* Translate:  Translate the aggregator-microservices readme to Spanish [Issue #2335 (Task of issue #2277 )]

* Translate:  Translate the aggregator-microservices readme to Spanish [Issue #2335 (Task of issue #2277 )]

* Update README.md

* Restored translated YAML Frontmatter keys to right words not translated and minor new changes

Minor new changes are at YAML Frontmatter variables values of lines 2 and 3 where have switched the order of translated words to homogeinize the belowing structure of that order like figured at following lines 6,7 and 8 (First english term and then Spanish translation between parenthesis)

* Update localization/es/aggregator-microservices/README.md

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>

* Update localization/es/aggregator-microservices/README.md

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>

* Update localization/es/aggregator-microservices/README.md

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>

* Update localization/es/aggregator-microservices/README.md

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>

* Update localization/es/aggregator-microservices/README.md

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>

* Translated ambassador pattern README.md to Spanish(#2453)

* Changed Class Diagram image path to absolute way.

The original path for Class Diagram image was relative to /ambassador folder (./etc/ambassador.urm.png) when translated at line 173 of translation doesn't show the diagram image so I haved changed it to absolute format (/ambassador/etc/ambassador.urm.png) and now it shows it.

* Added arrange-act-assert folder with README file without being traslated yet

* Translated line by line to spanish. English lines left for review, will be removed on next commit inmediately.

* Translated arrange-act-assert/README.md to Spanish and removed the English version text lines.

* Changed language tag value from en to es

* async-method-invocation translated to Spanish. Left the original English version lines for review and will be removed in next commit inmediately.

* async-method-invocation transalation to spanish. Removed the english version after review.

---------

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
2023-03-12 16:32:04 +02:00
..

title, category, language, tag
title category language tag
Arrange/Act/Assert Idiom es
Testing

También conocido como

Dado/Cuando/Entonces

Intención

Arrange/Act/Assert (AAA) es un patrón para organizar UnitTests. Divide las UnitTests en tres pasos claros y diferenciados:

  1. Arrange(Organizar): Realiza la configuración y la inicialización necesarias para el test.
  2. Act(Actuar): Toma las medidas necesarias para el test.
  3. Assert(Afirmar): Verifica los resultados del test.

Explicacación

Este patrón tiene varios beneficios significativos. Crea una clara separación entre la configuración, operaciones y resultados de un test. Esta estructura hace que el código sea más fácil de leer y comprender. Si colocas los pasos en orden y formateas su código para separarlos, puedes escanear un test y comprender rápidamente lo que hace.

También impone un cierto grado de disciplina cuando escribes tus UnitTests. Tienes que visualizar claramente los tres pasos que tu test realizará. Esto hace que los tests sean más intuitivos de escribir a la vez que tienes presente un esquema.

Ejemplo cotidiano

Necesitamos escribir un conjunto de UnitTests completo y claro para una clase.

En otras palabras

Arrange/Act/Assert es un patrón de testeo que organiza las pruebas en tres pasos claros para facilitar su mantenimiento.

WikiWikiWeb dice

Arrange/Act/Assert es un patrón para organizar y dar formato al código en los métodos UnitTest.

Código de ejemplo

Veamos primero nuestra clase Cash para que sea testeada.

public class Cash {

  private int amount;

  Cash(int amount) {
    this.amount = amount;
  }

  void plus(int addend) {
    amount += addend;
  }

  boolean minus(int subtrahend) {
    if (amount >= subtrahend) {
      amount -= subtrahend;
      return true;
    } else {
      return false;
    }
  }

  int count() {
    return amount;
  }
}

Luego escribimos nuestras UnitTests en función del patrón Arrange/Act/Assert. Note claramente la separación de los pasos para cada UnitTest.

class CashAAATest {

  @Test
  void testPlus() {
    //Arrange
    var cash = new Cash(3);
    //Act
    cash.plus(4);
    //Assert
    assertEquals(7, cash.count());
  }

  @Test
  void testMinus() {
    //Arrange
    var cash = new Cash(8);
    //Act
    var result = cash.minus(5);
    //Assert
    assertTrue(result);
    assertEquals(3, cash.count());
  }

  @Test
  void testInsufficientMinus() {
    //Arrange
    var cash = new Cash(1);
    //Act
    var result = cash.minus(6);
    //Assert
    assertFalse(result);
    assertEquals(1, cash.count());
  }

  @Test
  void testUpdate() {
    //Arrange
    var cash = new Cash(5);
    //Act
    cash.plus(6);
    var result = cash.minus(3);
    //Assert
    assertTrue(result);
    assertEquals(8, cash.count());
  }
}

Aplicabilidad

Utilice el patrón Arrange/Act/Asert cuando

  • Necesites estructurar tus UnitTests para que sean más fáciles de leer, mantener y mejorar.

Créditos