# PreTest/PostTest tasks, i.e. before() and after() tasks in Simulation execution

**URL:** <https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299>\
**Category:** Gatling (Open-Source)\
**Created:** [September 11, 2023, 3:10pm UTC](https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299 "2023-09-11T15:10:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pujitha](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pujitha](https://community.gatling.io/u/pujitha)\
**Post date:** [September 11, 2023, 3:10pm UTC](https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299/1 "2023-09-11T15:10:19Z")

</div>

Hello Gatling Explores/Experts,

I have a requirement to run set of as shell commands/Java methods before executing my Simulation and another set of shell/Java methods after completing the Simulation. I use Gatling Java 3.9.0 and my Simulation setup looks like below. Unfortunately the before() and after() blocks doesn’t let me add any statements.

Any idea how I can get this setup working? Highly appreciate all your thoughts. Thanks.

```java
public class BaselineSimulation extends Simulation {
  ConsumerJourney consumerJourney = new ConsumerJourney();
  {
    before(
      // need pre test tasks to run here
    );
    setUp(
       consumerJourney.getLoginLogoutJourney();
    )
 .assertions(assertionHelper.getResponseTimeAssertions());
    after(
      // need post test/cleanup tasks run here.
     );
   }
}

```

Kind regards

Pujitha

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 11, 2023, 3:17pm UTC](https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299/2 "2023-09-11T15:17:44Z")

</div>

> [@pujitha](#):
>
> Unfortunately the before() and after() blocks doesn’t let me add any statements.

Please properly read the documentation: [https://gatling.io/docs/gatling/reference/current/core/simulation/#hooks](https://gatling.io/docs/gatling/reference/current/core/simulation/#hooks)

In Gatling Java, these are methods to override.

---

<div class="post-metadata">

**Author:** ![pujitha](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@pujitha](https://community.gatling.io/u/pujitha)\
**Post date:** [September 11, 2023, 3:28pm UTC](https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299/3 "2023-09-11T15:28:20Z")

</div>

Ah, Thanks Stéphane.

yes, I should have read the documentation before posting here.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 11, 2023, 9:37pm UTC](https://community.gatling.io/t/pretest-posttest-tasks-i-e-before-and-after-tasks-in-simulation-execution/8299/4 "2023-09-11T21:37:15Z")

</div>

Closed on September 11, 2023, 9:37pm UTC


