Test heartbeating in service called within an activity

I have an activity that calls a service to perform a certain functionality. Inside my service method, I have a loop in which the service is performing heartbeats.
I am trying to test this service method and getting the following error:

ActivityExecutionContext can be used only inside of activity implementation methods and in the same thread that invoked an activity.

I tried to mock the static method Activity.getExecutionContext to return a mocked ActivityExecutionContext but still stuck with the same error.

Use TestActivityEnvironment to test activities.

Hello @maxim thanks for you reply,
How can I use TestActivityEnvironment here in this case. I already use it to test activities but in this case I am testing a service class that is being called within an activity, not the activity itself.

Create a fake test-only activity that implements the testing scenario.