开发者

Setting up maven resources when testing

I need resource goal of resource plugin to be set up differently for test phase, than for build phase. When testing I need to exclude stuff from src/main/resources. It seems it can't be done, testResources goal is irrelevant for what I need and resource goal can have only one setting in pom definition, that takes effect in both test and build phase...

For example, I'd need following settings to look differently (some excludes) in testing phase :

           <resources&g开发者_运维问答t;
             <resource>
               <directory>${project.basedir}/src/main/java</directory>
               <includes>
                   <include>**/*.java</include>
                   <include>service.properties</include>
               </includes>
             </resource>
             <resource>
               <directory>${project.basedir}/src/main/resources</directory>
               <includes>
                   <include>**/*.xml</include>
                   <include>**/*.properties</include>
               </includes>
             </resource>
           </resources>

The ideal behavior would be if I could define "src/main/*" in <testResources> but it unfortunately can't be done right now

Please help, I'd have to do tons of code modification if I didn't figure it out.


You would probably have to have the resources as a separate project that is not included at test time, which is a mess.

I can imagine why you would want to do this, but you aren't really testing the artifact at that point.

This is where IoC really shines. Your components get their resources injected instead of the component having to have runtime selection code of which resource (test or actual) that should be chosen. This is important because the test code can't test the code that chooses the test. If you see what I mean :-)

If you are using Spring, you can create a test-context.xml containing bean overrides for the changes you want to make, then load that after loading all your other contexts. When it is loaded, you will get a warning that the beans are being overridden, look at them closely the first time to be sure the test bean is overriding the production bean. Then that bean should be injected as you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜