Grails Spock unit test requires to mock transaction manager
<p>In Grails 3.1.12, I want to unit test a service:</p>

<pre><code>@Transactional
class PlanService {
    List&lt;Plan&gt; getPlans(Map params) {
        def currentUser = (User)springSecurityService.getCurrentUser()
        return Plan.findAllByCompany(currentUser.employer, params)
    }
}
</code></pre>

<p>Like this:</p>

<pre><code>@TestFor(PlanService)
@Mock([Plan, User, Company])
class PlanServiceSpec extends Specification {
    void "Retrieve plan from the current user"() {
        setup:
        // create and save entities here

        when: "the plans are retrieved"
        def params = null
        def plans = service.getPlans(params)

        then: "the result should only include plans associated to the current user's company"
        plans.size() == 2
}
</code></pre>

<p>Running the test from the console:</p>

<pre><code>grails&gt; test-app my.PlanServiceSpec -unit
</code></pre>

<p>Fails with:</p>

<pre><code>my.FundingPlanServiceSpec &gt; Retrieve plan from the current user FAILED
java.lang.IllegalStateException at PlanServiceSpec.groovy:48
</code></pre>

<p>and in the test report (HTML):</p>

<pre><code>java.lang.IllegalStateException: No transactionManager was specified.
Using @Transactional or @Rollback requires a valid configured transaction manager.
If you are running in a unit test ensure the test has been properly configured
and that you run the test suite not an individual test method.
</code></pre>

<p>Now if I comment out the <code>@Transactional</code> annotation in the service, the test passes, but that's not the intended implementation. I am able to work around the problem by mocking the transaction manager:</p>

<pre><code>service.transactionManager = Mock(PlatformTransactionManager) {
    getTransaction(_) &gt;&gt; Mock(TransactionStatus)
}
</code></pre>

<p>But this seems very awkward, if not wrong.</p>

<p>Is there some incantation I forgot to invoke?</p>

<p><em>EDIT:</em> looks similar to <a href="https://github.com/grails/grails-core/issues/1501" rel="noreferrer">an old bug</a>, but it's been closed more than a  year.</p>