Reputation: 4435
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
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