You would need to build the logic at your end. TestNG does not provide you out of the box implementations for such ask.
You can start off by defining a base class which implements an IHookable listener. All your test classes would extend this base class.
Within your base class'es IHookable's implementation, you define whatever isolation logic you need.
All that TestNG does when you say run tests in parallel is :
- Defines a thread pool executor with a size that matches the thread count as specified in your suite file.
- Builds a directed acyclic graph which would ensure that independent tests run first followed by dependent tests
- Runs through this graph coupled with the executorservice.