I'm working on the unit tests for Objectify-Appengine, which is a "mid-
level" persistence API for Google App Engine/Java (lower level than
JDO, higher level than the Low-Level API). Our unit tests are built
with TestNG and all roughly work like this:
* Set up the environment in a @BeforeMethod method.
* Run some data manipulation commands.
* Verify the data.
Pretty run-of-the-mill stuff, and it works great. However, I just
added a caching layer to Objectify which users can enable on a class
by class basis. Now I want to run all my unit tests twice, once with
caching enabled and once with caching disabled.
I thought I might be able to use a @DataProvider with my "Set up the
environment" @BeforeMethod, but that doesn't seem to be available.
What is the recommended solution for this pattern? Surely this must
have come up before - there is some bit of state in the system that
could possibly produce different behavior, so all unit tests need to
be run at each state. Adding @DataProvider parameters to every single
test method would be onerous.
Thanks,
Jeff
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
I had hoped that the semantic for @DataProvider on @BeforeMethod would
mean that every test that uses the @BeforeMethod would run N times,
once with the @BeforeMethod called with the first parameter, once with
the @BeforeMethod called with the second parameter, etc... obviously
there's potential for a multiplicative explosion with multiple
@BeforeMethods and the @DataProvider on the test method itself, but
this is exactly what would be most useful, no? Essentially:
class MyTests {
@DataProvider(name="states")
public Object[][] generateStates() { ... }
@DataProvider(name="values")
public Object[][] generateValues() { ... }
@BeforeMethod(dataProvider="states")
public void setUp(String state) { ... }
@Test(dataProvider="values")
public void testSomething(String value) { ... }
}
Ideally this would end up testing every value for every state. In
practice, the @BeforeMethod would be on a base class and there might
be hundreds of tests with varying data providers that all would be
tested with each state.
> The traditional way to approach this problem is to use @Factory. In your
> factory, you now create one instance of your test class per set of values,
> the constructor of your class stores these values in fields and you can then
> use them in your @Before methods whenever you need them. This preserves the
> semantics of all the configuration methods and it should solve your problem
> completely.
>
> What do you think of this approach?
It is less satisfying than what I described above, but modifying every
class beats the hell out of modifying every single test method.
Can I put @Factory methods on the test classes themselves? If there's
a chicken-and-egg problem with the constructor, can I put the @Factory
method on a static inner class of the test class? Will these @Factory
methods get picked up by Eclipse automatically or do I need a
testng.xml file to specify the factories? The documentation seems
unclear on this point.
I'm trying to avoid a single class that must instantiate all the other
test classes, since it will inevitably get out of sync with multiple
people working in the project.
Thanks!
Jeff
Thanks!
Jeff
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Can you please show us the code so that we can try and execute it to recreate the problem ?
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/3Kny3qTVdmg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.
Rahul
I was hoping that you would share a sample that can be used to execute and recreate the problem.
I am not able to recreate your problem when I created a simple test.
Have you tried creating a simple test which just uses sysout statements and see if you are able to recreate the problem ? If not then am afraid the bug perhaps lies in your logic.
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.