I am using Groovy for my Spring application and I try to use multiple XML beans configurations inside my test. I tried using @ContextHierarchy but following usage example didn't work:
@RunWith(SpringRunner)
@SpringBootTest
@ContextHierarchy({@ContextConfiguration("a.xml"), ContextConfiguration("b.xml")})
public class MyTest {
...
}
I have also tried:
@ContextConfiguration(locations={"a.xml", "b.xml"})
but it didn't work as well.
As I understand Groovy doesn't like the "{" "}", because it has different mean to it....?
How can I write the Testclass in groovy with two conifiguration xmls defined?
You can define multiple XML configuration sources with
@ContextConfigurationannotation. Let's say I have 2 XML config files located insrc/main/resources-beans1.xmlandbeans2.xml. I can use them in my test with:The main difference comparing to Java is that Groovy uses
[]for arrays instead of Java's{}, because{}represents Groovy's closure.