Question

I am fairly new to Griffon and have some experience with Grails.

I have a problem loading a file from the resources directory.

I am using Griffon version 1.4.0.

When I run griffon run-app the following code (inside a Service) to get the location of an XML file works fine:

URL resource = getResourceAsURL('schema.xsd')
assert resource != null : "schema cannot be located"

When I run griffon test-app however the same code produces an assertion error because the returned URL is null. Same behaviour with getResourceAsStream().

This happens in the unit test of said service.

I put the file in ./griffon-app/resources.

What am I doing wrong? Do I have to copy all resources from production to some test resources folder, do I have to edit the build-configuration?

Thanks in advance!

Edit as suggested below I filed a bug report in the griffon-projects issue tracker.

Was it helpful?

Solution

araxn1d is correct, running the tests in integration mode will give you the right answer because the full application gets bootstrapped before tests are run. Now, running this kind of test (a unit test that depends on resources being available in the classpath) encounters a problem because the classpath is not setup correctly. Executing the following command

griffon -Dgriffon.cli.verbose=true test-app --unit --compileTrace=true

will output all classpaths. There you can see that the resources directory points to $USER_HOME/.griffon/1.4.0/projects/<project_name>/resources. If you inspect that directory you'll find the file you're looking for inside griffon-app/resources. This means the test classpath is not accurately configured as it should be $USER_HOME/.griffon/1.4.0/projects/<project_name>/resources/griffon-app/resources instead. This is clearly a bug, most likely found in the $GRIFFON_HOME/scripts/_GriffonClasspath.groovy script. Could you please file a JIRA http://jira.codehaus.org/browse/griffon ticket for it? Thanks!

OTHER TIPS

You should run test-app to run your unit tests. In this case you should mock any refers to real files, otherwise you should implement Integration Tests. Pls see Griffon Testing. Integration tests differ from unit tests in that you have full access to the Griffon application within the test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top