@BeforeGroups and @Factory

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

@BeforeGroups and @Factory

Dmitri Priimak
Hi All.

I am having a small problem that is probably result of misunderstanding. In the following example

public class TestTest {
   
@Factory
   
public Object[] provideTestInstances() {
       
return new Object[] {new TC(1), new TC(2)};
   
}

   
public static final class TC {
       
private final int index;

        TC
(int index) {
           
this.index = index;
       
}

       
@Test(groups = {"one"})
       
public void testOne() {
           
System.out.println("One");
       
}

       
@Test(groups = {"two"}, dependsOnGroups = {"one"})
       
public void testTwo() {
           
System.out.println("Two");
       
}

       
@BeforeGroups(groups = {"two"})
       
public void inBetween() {
           
System.out.println("inBetween " + index);
       
}
   
}
}


I see method inBetween() executed only once from the first instance of TC class instead of what I expected to be twice.
Is that the expected behavior? If so what is suggested course of action to have it executed once in each instance of TC class?

--
Dmitri Priimak

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @BeforeGroups and @Factory

Dmitri Priimak
Just to follow up. The output of running these tests is

One
One
inBetween 1
Two
Two

While personally I was expecting to see function inBetween(...) called twice in both instances of class TC. 

On Saturday, December 2, 2017 at 11:37:00 AM UTC-8, Dmitri Priimak wrote:
Hi All.

I am having a small problem that is probably result of misunderstanding. In the following example

public class TestTest {
   
@Factory
   
public Object[] provideTestInstances() {
       
return new Object[] {new TC(1), new TC(2)};
   
}

   
public static final class TC {
       
private final int index;

        TC
(int index) {
           
this.index = index;
       
}

       
@Test(groups = {"one"})
       
public void testOne() {
           
System.out.println("One");
       
}

       
@Test(groups = {"two"}, dependsOnGroups = {"one"})
       
public void testTwo() {
           
System.out.println("Two");
       
}

       
@BeforeGroups(groups = {"two"})
       
public void inBetween() {
           
System.out.println("inBetween " + index);
       
}
   
}
}


I see method inBetween() executed only once from the first instance of TC class instead of what I expected to be twice.
Is that the expected behavior? If so what is suggested course of action to have it executed once in each instance of TC class?

--
Dmitri Priimak

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.