You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Kevin Burton <bu...@spinn3r.com> on 2015/10/04 01:20:56 UTC

Best way to keep test resources with junit / surefire /maven.

I'm trying to figure out if there's a better way to do this.

Java doesn't support "here files" or embedded files.... so you have to keep
your resources external.  Usually in 'resources',

I don't want to have things like HTML code and other things in my tests as
it makes the tests ugly.

But the problem is that once I create the resources, they can't participate
in refactoring.

At least in intellij... even if it's *OBVIOUS* that the resource is
associated with a given test.

Is there a cleaner way to do this?

Either this whole thing is broken or I'm doing it wrong.

-- 

We’re hiring if you know of any awesome Java Devops or Linux Operations
Engineers!

Founder/CEO Spinn3r.com
Location: *San Francisco, CA*
blog: http://burtonator.wordpress.com
… or check out my Google+ profile
<https://plus.google.com/102718274791889610666/posts>

Re: Best way to keep test resources with junit / surefire /maven.

Posted by Jason van Zyl <ja...@takari.io>.
In almost all cases I start a new project with actual resources in the files system to prototype and make sure a new system is working but this becomes untenable fairly quickly for the reasons you mention vis-a-vis refactoring.

Ultimately what I end up with is a small generative utility for the type of resource I need. In the recent past that’s been class files, JAR files, Git repos, and JSON documents. Whatever resource I happen to need I create a tool, test the tool, and have it emit resources into the target directory that are used for tests and they get wiped out and regenerated with every clean build. In making changes to the generative tools I usually leave all tests intact and only make additive changes to the generative tool as not to break the output that’s expected.

This is the best method that I’ve found. It takes some time to build the generative tool but I find it’s worth it. Trying to manage actual resources as your code and tests get more sophisticated get cumbersome very quickly.

> On Oct 3, 2015, at 7:20 PM, Kevin Burton <bu...@spinn3r.com> wrote:
> 
> I'm trying to figure out if there's a better way to do this.
> 
> Java doesn't support "here files" or embedded files.... so you have to keep
> your resources external.  Usually in 'resources',
> 
> I don't want to have things like HTML code and other things in my tests as
> it makes the tests ugly.
> 
> But the problem is that once I create the resources, they can't participate
> in refactoring.
> 
> At least in intellij... even if it's *OBVIOUS* that the resource is
> associated with a given test.
> 
> Is there a cleaner way to do this?
> 
> Either this whole thing is broken or I'm doing it wrong.
> 
> -- 
> 
> We’re hiring if you know of any awesome Java Devops or Linux Operations
> Engineers!
> 
> Founder/CEO Spinn3r.com
> Location: *San Francisco, CA*
> blog: http://burtonator.wordpress.com
> … or check out my Google+ profile
> <https://plus.google.com/102718274791889610666/posts>

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder, Takari and Apache Maven
http://twitter.com/jvanzyl
http://twitter.com/takari_io
---------------------------------------------------------

the course of true love never did run smooth ...

 -- Shakespeare













---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Best way to keep test resources with junit / surefire /maven.

Posted by Martin Gainty <mg...@hotmail.com>.
> From: burton@spinn3r.com
> Date: Sat, 3 Oct 2015 16:20:56 -0700
> Subject: Best way to keep test resources with junit / surefire /maven.
> To: users@maven.apache.org
> 
> I'm trying to figure out if there's a better way to do this.
> 
> Java doesn't support "here files" or embedded files.... so you have to keep
> your resources external.  Usually in 'resources',
> 
> I don't want to have things like HTML code and other things in my tests as
> it makes the tests ugly.
> 
> But the problem is that once I create the resources, they can't participate
> in refactoring.
> 
> At least in intellij... even if it's *OBVIOUS* that the resource is
> associated with a given test.

MG>on possibility is to define additional directory in resources
<resources>

     <resource>
       
    <directory>HTMLFolderGoesHere</directory>
  <resource>
</resources>

<!-- or possibly add in the folder as a additional classpath element for maven surefire to act upon -->
  <plugin>
        
     <grouplId>org.apache.maven.plugins</groupId>

     <artifactId>maven-surefire-plugin</artifactId>

     <version>2.18.1</version>
        
    <configuration>

      <additionalClasspathElements>HTMLFolderGoesHere</additionalClasspathElement>
MG>would this work?


> 
> Is there a cleaner way to do this?
> 
> Either this whole thing is broken or I'm doing it wrong.
> 
> -- 
> 
> We’re hiring if you know of any awesome Java Devops or Linux Operations
> Engineers!
> 
> Founder/CEO Spinn3r.com
> Location: *San Francisco, CA*
> blog: http://burtonator.wordpress.com
> … or check out my Google+ profile
> <https://plus.google.com/102718274791889610666/posts>