Writing Tests for components that require some core setup

48 views
Skip to first unread message

Cosmin Stefan-Dobrin

unread,
Sep 20, 2013, 11:06:34 AM9/20/13
to zaproxy...@googlegroups.com
Hi,

I was working on a couple of tests for some of the Authentication related functionality recently added to the trunk and I got a bit stuck (I have to admit I'm not extremely experienced with tests setting up).

Well, I've pulled the zap-tests repo and I've set everything up ok => no compile errors. In order to test some of the functionality, I need some core parts of ZAP to be set up: Control, Model, Sessions etc. so I can actually send HttpMessages from inside the tests. I've found some test code [1] related that loads parts of ZAP. But, when running, I've noticed that all the tests which use the WithBasicInfrascturure fail do to some issues with loading resource bundles. E.g. (while running the HttpProxyConnectionIntegrationTest:

java.util.MissingResourceException: Can't find bundle for base name Messages, locale de_DE
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
    at org.zaproxy.zap.utils.I18N.<init>(I18N.java:28)
    at org.parosproxy.paros.Constant.setLocale(Constant.java:645)
    at org.parosproxy.paros.core.proxy.WithBasicInfrastructureIntegrationTest.initializeLocale(WithBasicInfrastructureIntegrationTest.java:88)
    at org.parosproxy.paros.core.proxy.WithBasicInfrastructureIntegrationTest.setup(WithBasicInfrastructureIntegrationTest.java:84)
...
   

Any hints about fixing this problem? Or, even better, on how to set up such tests that require, for example, the ZAP's HTTPSender to be initialized?

Cosmin Stefan-Dobrin

unread,
Sep 21, 2013, 8:32:30 AM9/21/13
to zaproxy...@googlegroups.com
After a bit more digging into the problem, I've realized that Resources are resolved from the class directory. And since the resource files are not copied to the output folder of the zaproxy-test project, they can't be found. However, I have no idea how to fix this. Maybe I didn't set something up while configuring the project? Any ideas?

Thanks,
Cosmin

--
Cosmin

psiinon

unread,
Sep 23, 2013, 7:40:37 AM9/23/13
to zaproxy...@googlegroups.com
Hey Cosmin,

Looks like the tests are failing - I'm guessing that they havnt needed any resource files before now?
How about just copying the resources into the output folder?
I wouldnt have a problem with that :)

Cheers,

Simon

Cosmin Stefan-Dobrin

unread,
Sep 23, 2013, 7:52:43 AM9/23/13
to zaproxy...@googlegroups.com
Well, some of the already existing Integration tests (the ones that were using some components that require resources) were already failing for me. And now, I've also added a couple of tests that fail due to missing resources if I don't manually change the statically loaded messages to some random strings. So I guess that the problem has been here for some time or only I have a problem with the project setup.

Regarding copying the resources to the output folder, I have no idea on how to do that dynamically (so as we don't have to import the messages.properties file manually whenever we run the tests).

--
Cosmin


--
You received this message because you are subscribed to the Google Groups "OWASP ZAP Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zaproxy-devel...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Cosmin Stefan-Dobrin

unread,
Sep 23, 2013, 7:57:52 AM9/23/13
to zaproxy...@googlegroups.com
Maybe we can use something like suggested here: [1]? We could have some sort of basic/core ZAP initializer and in there Mock (or Spy) on the real Constant.java and make it load the properties files from the other project somehow?

PS: I have to admit I don't have a lot of experience on this so maybe I'm saying stupid things :)

[1] - http://stackoverflow.com/questions/13699153/how-to-read-string-from-properties-file-in-junit-tests

--
Cosmin

psiinon

unread,
Sep 23, 2013, 7:58:39 AM9/23/13
to zaproxy...@googlegroups.com
How are you running the tests?
I run them via the Ant build file and I only see one test failing right now - CookieBasedSessionManagementMethodType

Cheers,

Simon

Cosmin Stefan-Dobrin

unread,
Sep 23, 2013, 8:52:05 AM9/23/13
to zaproxy...@googlegroups.com
Hi,

I was running them via Eclipse -> Run As -> JUnit Test. I followed the guide at: https://code.google.com/p/zaproxy-test/wiki/EclipseWorkspaceSetup , where I didn't see any mentions regarding the build.xml file. Maybe we can update the instructions there if the only way to make it work is to run it from there?

Anyway, I've now tried to run it using the build file and I don't seem to get past the compilation. The steps I took were:
  1. build the Zaproxy project via its build.xml
  2. build the Zaproxy-Extensions project via its build.xml
  3. run the 'test' target of the Zaproxy-tests build.xml

However, it doesn't seem able to identify some symbols from the Zaproxy-Extension project. Example:   

[javac] /home/cosmin/zaproxy/tests/src/org/parosproxy/paros/core/proxy/WebSocketsConnectionIntegrationTest.java:41: error: cannot find symbol
    [javac] import org.zaproxy.zap.extension.websocket.ExtensionWebSocket;
    [javac]                                           ^
    [javac]   symbol:   class ExtensionWebSocket
    [javac]   location: package org.zaproxy.zap.extension.websocket

Am I missing something?


--
Cosmin

Cosmin Stefan-Dobrin

unread,
Sep 23, 2013, 10:59:43 AM9/23/13
to zaproxy...@googlegroups.com
Hi,

First of all, I still have the issues presented in the previous email, but, for the sake of seeing if the original problem is solved, I've deleted all the 'zaproxy-extensions' tests so I can compile. Also, I've noticed that the failed test you mentioned was because of a NullPointerException because of Constant.messages not being initialized. So I initialized it in the tests. And now the error I'm getting is the one I was mentioning in the original email: "java.util.MissingResourceException: Can't find bundle for base name Messages".

Also, I've noticed that none of the 'Integration' tests are being included in the ZaproxyIntegrationTestSuite, probably due to the same problem, because when I manually run them in Eclipse I also see the MissingResourceException.


Any ideas on how to include the Resources in the tests?

--
Cosmin

Cosmin Stefan-Dobrin

unread,
Sep 24, 2013, 10:58:01 AM9/24/13
to zaproxy...@googlegroups.com
Hi,

I've managed to find a clean and nice way to get rid of the issues (when running using JUnit in Eclipse). So I think maybe we should add an extra step to the Eclipse Workspace Configuration for the tests:
5.5. Add zaproxy's localization files to the classpath (via Properties -> Java Build Path -> Source -> Link Source and select the zaproxy/src/lang folder)

After this command, a simple call to Constant.getInstance() in the test setup will make sure that messages are properly loaded.

How does it sound?


--
Cosmin
Reply all
Reply to author
Forward
0 new messages