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();
}
}
Yes, use the same annotations in your groovy file. As long as groovy is in your class path, it should just work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With