# Orden de ejecucion

Para establecer el orden de ejecución

## Ejecución simultanea

Todos se ejecutan al iniciar al contenedor. Se utiliza la anotación **@DependsOn("TestEnvironment")**

![](/files/-Lc1Wnoe7u6ccYJpNtgD)

## Ejecución Dependiente

En algunas ocasiones debemos indicar el orden de ejecución de los Test.

Las reglas serian:

* La clase principal debe implementar **@DependsOn("TestEnvironment")**
* Las clases secundarias implementan @DependsOn("nombre-clase-que-debe-ejecutarse-primero")

![](/files/-Lc1Wnogj7e-Ub-WZL-_)

## Proyecto Web

En el proyecto Web siempre usamos el orden de ejecuciòn dependiente, ya que necesitamos invocar el método terminate() del unitTest en el ultimo test que realicemos.

En este ejemplo BodegaTest.java se ejecutara primero y ColorTest.java sera el ultimo en ejecutarse e invocara el terminate()

![](/files/-Lc1Wnoi5wEESOV9ruf4)

## **BodegaTest.java**

* Definimos que es dependiente de TestEnvironment y la ruta para los reportes.

```java
@Startup
@Singleton
@DependsOn("TestEnvironment")
@Test
@Report(path = "/home/avbravo/Descargas/")
public class BodegaTest {

    @Inject
    UnitTest unitTest;
    @Inject
    BodegaRepository bodegaRepository;

    @PostConstruct
    void init() {
        unitTest.start(BodegaTest.class);

      ....

    }

    @PreDestroy
    public void destroy() {
        unitTest.end(BodegaTest.class);
    }

    ...
    }
```

## ColorTest.java

* Depende de BodegaTest
* Como es el ultimo test en ejecutarse invoca **unitTest.terminate()** desde el método init().

```java
@Startup
@Singleton
@DependsOn("BodegaTest")
@Test
public class ColorTest {

    @Inject
    UnitTest unitTest;
    @Inject
    UnitView unitView;
    @Inject
    ColorRepository colorRepository;

    @PostConstruct
    void init() {
        unitTest.start(ColorTest.class);
        unitView.start(ColorTest.class);
    ......
  unitTest.terminate();
    }

    @PreDestroy
    public void destroy() {
        unitTest.end(ColorTest.class);
    }
    ......
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://avbravo-2.gitbook.io/jmoordbunit/proyecto-web/orden-de-ejecucion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
