Java – JUnit external resource @ rule order
•
Java
I want to use multiple external resources in my test class, but I have a problem sorting external resources
This is a 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 that it tries to start the pig before Hadoop starts, so I can't connect to the local Hadoop single node cluster
Is there any way to order JUnit rules?
thank you
Solution
You can use rulechain
@Rule public TestRule chain= RuleChain.outerRule(new HadoopSingleNodeCluster()) .around(new PigExternalResource());
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码