Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
    }

}
like image 232
myborobudur Avatar asked Jun 27 '26 12:06

myborobudur


1 Answers

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

like image 145
ataylor Avatar answered Jun 29 '26 07:06

ataylor