You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by MeriƧ Taze <me...@gmail.com> on 2012/07/09 09:33:13 UTC

Is it possible to make an static TestReference

Hi,
I have a problem with sling test tool. Let me give an example about the
problem:

@TestReference
private static MyClass myClass;

@BeforeClass
public static void beforeClass(){
  myClass.create();
}

@Test
.....

@AfterClass
public static void afterClass(){
  myClass.remove();
}

I created a test class similar to above example. However, I cannot get
testreference
because of "static" keyword, and I also cannot remove static keyword from
myClass
since beforeclass and afterclass want to be everything static.

I decide to use create and remove inside @Before and @After annotations by
using
a counter i.e. if(counter==0) inside @Before and if(counter==TESTCOUNT)
inside
@After, and increase my counter inside each @Test.

I want to know is it possible solve my problem with BeforeClass and
AfterClass ?

Regards,
Meric.

Re: Is it possible to make an static TestReference

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Mon, Jul 9, 2012 at 9:33 AM, MeriƧ Taze <me...@gmail.com> wrote:
> I have a problem with sling test tool....

> @TestReference
> private static MyClass myClass;

That should work, I haven't tested it but looking at the code this
will only be set once an instance of the test test object is
created...

>
> @BeforeClass
> public static void beforeClass(){
>   myClass.create();
> }

...and the @BeforeClass method is probably caused before that happens,
so myClass wouldn't be set yet.

For now, as you indicate, the best might be to use @Before methods
that setup myClass only if it hasn't been setup yet.

-Bertrand