myborobudur
myborobudur

Reputation: 4435

Can I write spring java tests in groovy?

I have a junit test in the spring environment with dependency injection in java.

I'm interested in groovy and would like to write my tests with it.

How would look the following test in groovy?

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "/META-INF/spring/context.xml")
public class DITestJava {

    @Inject
    WriteController wc;
    @Inject
    ReadController rc;

    @Test
    public void diTest() {
        Assert.assertNotNull(wc);
        Assert.assertNotNull(rc);

        wc.doConfig();
        rc.printConfig();
    }

}

Upvotes: 3

Views: 2189

Answers (1)

ataylor
ataylor

Reputation: 66059

Yes, use the same annotations in your groovy file. As long as groovy is in your class path, it should just work.

Upvotes: 1

Related Questions