You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by rolfst <ro...@gmail.com> on 2009/07/26 11:12:08 UTC
Testify injection only works once per test
Hi I am using Testify to inject a fake repository into my testng test but I
come op to a problem.
when i first access the fake repository it gets injected however the second
time i access the repository I get a null pointer exception.
Now comes another strange thing when i debug everything works fine and the
repository gets injected perfectly.
Any ideas?
Regards,
Rolf
--
View this message in context: http://www.nabble.com/Testify-injection-only-works-once-per-test-tp24665202p24665202.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify injection only works once per test
Posted by Paul Field <pa...@db.com>.
Paul Field <pa...@db.com> wrote on 28/07/2009 09:35:05:
> rolfst <ro...@gmail.com> wrote on 27/07/2009 14:13:51:
> > Yes there are three groups involved in the suite.
> > How ever no other test from other groups are available.
> > It seems that when I remove the reference to groups in my testng.xml
it
> > works fine.
> >
> > For now a workable solution it looks like a bug though not sure wether
> > testng or testify.
>
> It's a bug in Testify :-) I've fixed it and it will be in the latest
> snapshot release. However, the build server on tapestry 360 is currently
> jammed, so we need to wait for that to be fixed before the snapshot is
> built and published.
FYI, Tapestry 360's build server is now working (has been for a couple of
days now i think) - so the lastest Testify Snapshot is available with the
bug fix for TestNG groups.
Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: Testify injection only works once per test
Posted by Paul Field <pa...@db.com>.
rolfst <ro...@gmail.com> wrote on 27/07/2009 14:13:51:
> Hi Paul,
>
> Yes there are three groups involved in the suite.
> How ever no other test from other groups are available.
> It seems that when I remove the reference to groups in my testng.xml it
> works fine.
>
> For now a workable solution it looks like a bug though not sure wether
> testng or testify.
It's a bug in Testify :-) I've fixed it and it will be in the latest
snapshot release. However, the build server on tapestry 360 is currently
jammed, so we need to wait for that to be fixed before the snapshot is
built and published.
Paul
> Paul Field wrote:
> >
> > rolfst <ro...@gmail.com> wrote on 27/07/2009 13:26:23:
> >
> >>
> >> @Test(groups = "rbudisplay")
> >> public void test_rbuselection_fulltype() throws Exception
> >> {
> >
> > Oooo... it might be something to do with groups. Is your suite
specifying
> > that only certain groups are run?
> >
> > (my brain aches whenever I try to work out what get runs in TestNG :-)
).
> >
> > Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: Testify injection only works once per test
Posted by rolfst <ro...@gmail.com>.
Hi Paul,
Yes there are three groups involved in the suite.
How ever no other test from other groups are available.
It seems that when I remove the reference to groups in my testng.xml it
works fine.
For now a workable solution it looks like a bug though not sure wether
testng or testify.
thanks anyway.
regards Rolf
Paul Field wrote:
>
> rolfst <ro...@gmail.com> wrote on 27/07/2009 13:26:23:
>
>>
>> @Test(groups = "rbudisplay")
>> public void test_rbuselection_fulltype() throws Exception
>> {
>
> Oooo... it might be something to do with groups. Is your suite specifying
> that only certain groups are run?
>
> (my brain aches whenever I try to work out what get runs in TestNG :-) ).
>
> Paul
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
>
--
View this message in context: http://www.nabble.com/Testify-injection-only-works-once-per-test-tp24665202p24680484.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify injection only works once per test
Posted by Paul Field <pa...@db.com>.
rolfst <ro...@gmail.com> wrote on 27/07/2009 13:26:23:
>
> @Test(groups = "rbudisplay")
> public void test_rbuselection_fulltype() throws Exception
> {
Oooo... it might be something to do with groups. Is your suite specifying
that only certain groups are run?
(my brain aches whenever I try to work out what get runs in TestNG :-) ).
Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: Testify injection only works once per test
Posted by rolfst <ro...@gmail.com>.
Hi Paul,
I have this test method
@Inject
private TestPageResultRetriever<RBUSelection> retriever;
@Inject
private RBUTypeRepository repository;
@Override
protected void doSetUp() throws Exception
{
}
@Test(groups = "rbudisplay")
public void test_rbuselection_fulltype() throws Exception
{
Document doc = tester.renderPage("multiselect/rbuselectiontestpage");
List<Element> selectelements =
TapestryXPath.xpath("//select").selectElements(doc);
assertEquals(selectelements.size(), 2);
Iterable<Element> options = getSelectElementOptions(doc,
"//table/tr[1]//select[1]");
assertEquals(Iterables.size(options), 3);
selectOptionElement(options, 1);
Element textfield =
TapestryXPath.xpath("//table/tr[1]//input[1]").selectSingleElement(doc);
textfield.forceAttributes("value", "1");
Iterable<Element> options2 = getSelectElementOptions(doc,
"//table/tr[2]//select[1]");
selectOptionElement(options2, 1);
Element hidden =
TapestryXPath.xpath("//table/tr[2]//input[1]").selectSingleElement(doc);
assertNotNull(hidden);
Element form = doc.getElementById("rbuselection");
tester.submitForm(form, new HashMap<String, String>());
RBUSelection selection = getSubmittedRBUSelection(1L);
assertNotNull(selection);
RBU rbu = selection.getSelection();
assertEquals(rbu.getId(), Long.valueOf(2L));
}
private RBUSelection getSubmittedRBUSelection(Long id)
{
RBUType type = repository.findById(id, false);
RBUSelection entry = new RBUSelection(type);
RBUSelection selection = retriever.getEntry(entry);
return selection;
}
When I run the test within a suite the test fails in the
getSubmittedRBUSelection method on the first statement which as you can see
is being called at the forth statement before the end of the testmethod.
the repository is already been used in the page aswell otherwise I would
have recieved an exception from there.
When i run the test alone with its class it works
Paul Field wrote:
>
> Hi Rolf,
>
>
>> Hi I am using Testify to inject a fake repository into my testng test
> but I
>> come op to a problem.
>>
>> when i first access the fake repository it gets injected however the
> second
>> time i access the repository I get a null pointer exception.
>>
>> Now comes another strange thing when i debug everything works fine and
> the
>> repository gets injected perfectly.
>
> At the moment Testify's TestNG integration is using @BeforeClass to
> process the @Inject annotations. So I can see that there might be possible
> scenarios that match yours: something where the '@Inject'ed field is
> cleared between tests for example... but it's hard to know exactly what's
> happening from your description.
>
> Could you give some more information (e.g. code examples) that show the
> problem? Also, when you debug, are you running exactly the same suite as
> when you aren't debugging? And is the behaviour consistent if you try this
> multiple times?
>
> Thanks,
>
> Paul
>
>
>
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and delete this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
>
--
View this message in context: http://www.nabble.com/Testify-injection-only-works-once-per-test-tp24665202p24679761.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify injection only works once per test
Posted by Christian Gruber <ch...@gmail.com>.
On Jul 27, 2009, at 6:25 AM, Paul Field wrote:
> If you are setting up state that you want to be fresh for each test,
> then
> you should consider using Testify's pertest scope:
> http://tapestry.formos.com/nightly/tapestry-testify/#Per-test_scope
Ah... this is what I was thinking - thanks for pointing it out.
Christian.
Christian Edward Gruber
christianedwardgruber@gmail.com
http://www.geekinasuit.com/
Re: Testify injection only works once per test
Posted by Paul Field <pa...@db.com>.
Christian Edward Gruber <ch...@gmail.com> wrote on
27/07/2009 11:07:41:
> I think that @BeforeMethod is a better one to key off-of. If
> singleton-scoped objects are the only ones being injected, then
> @BeforeClass makes sense, but if you're testing per-request or per-
> session objects, then it's best to use @BeforeMethod, since you may be
> setting state on these which needs to be fresh for each test.
As I understand the Tapestry IOC, it shouldn't make any difference.
Generally, service objects are actually proxy objects; with non-singleton
scopes the proxy object is responsible for forwarding calls to the correct
instance of the service. For example, to quote the documentation, "With
perthread, the service proxy will delegate to a local service instance
that is associated with the current thread. Two different threads,
invoking methods on the same proxy, will ultimately be invoking methods on
two different service instances, each reserved to their own thread."
See "Defining Service Scope" on:
http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
This ingenious feature is what allows Tapestry IOC to inject a per-thread
service into a singleton service and have that work correctly.
If you are setting up state that you want to be fresh for each test, then
you should consider using Testify's pertest scope:
http://tapestry.formos.com/nightly/tapestry-testify/#Per-test_scope
Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
Re: Testify injection only works once per test
Posted by Christian Edward Gruber <ch...@gmail.com>.
I think that @BeforeMethod is a better one to key off-of. If
singleton-scoped objects are the only ones being injected, then
@BeforeClass makes sense, but if you're testing per-request or per-
session objects, then it's best to use @BeforeMethod, since you may be
setting state on these which needs to be fresh for each test.
cheers,
Christian.
On 2009-07-27, at 05:00 , Paul Field wrote:
> Hi Rolf,
>
>
>> Hi I am using Testify to inject a fake repository into my testng test
> but I
>> come op to a problem.
>>
>> when i first access the fake repository it gets injected however the
> second
>> time i access the repository I get a null pointer exception.
>>
>> Now comes another strange thing when i debug everything works fine
>> and
> the
>> repository gets injected perfectly.
>
> At the moment Testify's TestNG integration is using @BeforeClass to
> process the @Inject annotations. So I can see that there might be
> possible
> scenarios that match yours: something where the '@Inject'ed field is
> cleared between tests for example... but it's hard to know exactly
> what's
> happening from your description.
>
> Could you give some more information (e.g. code examples) that show
> the
> problem? Also, when you debug, are you running exactly the same
> suite as
> when you aren't debugging? And is the behaviour consistent if you
> try this
> multiple times?
>
> Thanks,
>
> Paul
>
>
>
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this e-mail
> in error) please notify the sender immediately and delete this e-
> mail. Any unauthorized copying, disclosure or distribution of the
> material in this e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for
> additional EU corporate and regulatory disclosures.
Christian Edward Gruber
e-mail: christianedwardgruber@gmail.com
weblog: http://www.geekinasuit.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify injection only works once per test
Posted by Paul Field <pa...@db.com>.
Hi Rolf,
> Hi I am using Testify to inject a fake repository into my testng test
but I
> come op to a problem.
>
> when i first access the fake repository it gets injected however the
second
> time i access the repository I get a null pointer exception.
>
> Now comes another strange thing when i debug everything works fine and
the
> repository gets injected perfectly.
At the moment Testify's TestNG integration is using @BeforeClass to
process the @Inject annotations. So I can see that there might be possible
scenarios that match yours: something where the '@Inject'ed field is
cleared between tests for example... but it's hard to know exactly what's
happening from your description.
Could you give some more information (e.g. code examples) that show the
problem? Also, when you debug, are you running exactly the same suite as
when you aren't debugging? And is the behaviour consistent if you try this
multiple times?
Thanks,
Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.