Invoke a process (valgrind) before a test is run

Hello,
I’d like to run Valgrind in some of my tests to ensure there are no memory leaks with native code within the Java code. I have 2 acceptable means of testing which are:

  1. Run the tests in the same process as …
    ./gradlew test
    …to ultimately have the command
    valgrind {valgrind flags to detect memory leaks (e.g. --leak-check=yes ) } ./gradlew test
    …the problem with the line above is that the actual test is run in a separate process.

  2. Pass the executable command in the build.gradle file…
    build.gradle


test {
executable “valgrind {flags to detect memory leaks (e.g. --leak-check=yes ) } /opt/java/bin/java”
}

The code above will substitute ‘java’ with the valgrind command above and eventually execute java.

I haven’t figured out how to do #1 above and #2 fails with ‘executable’ in the test.

Can someone please help me?