Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Junit External Resource @Rule Order

I want to use multiple external resources in my test class, but I have a problem with ordering of external resources.

Here is code snippet :

public class TestPigExternalResource {

     // hadoop external resource, this should start first
     @Rule
     public HadoopSingleNodeCluster cluster = new HadoopSingleNodeCluster();

     // pig external resourcem, this should wait until hadoop external resource starts
     @Rule
     public  PigExternalResource pigExternalResource = new PigExternalResource(); 

     ...  
}

The problem is it tries to start pig before hadoop started, therefore I could not connect local hadoop single node cluster.

Is there any way to order rules of junit?

thanks

like image 806
Salih Kardan Avatar asked Oct 04 '13 07:10

Salih Kardan


1 Answers

You can use RuleChain.

@Rule
public TestRule chain= RuleChain.outerRule(new HadoopSingleNodeCluster())
                           .around(new PigExternalResource());
like image 130
Stefan Birkner Avatar answered Oct 12 '22 11:10

Stefan Birkner