How to inject parameter into constructor of TestNG class?

前端 未结 1 854
生来不讨喜
生来不讨喜 2020-12-21 12:51

I have implemented a programm with the strategy pattern. So I have an interface which is used at some places and the concrete implementation may be replaced.

Now I

相关标签:
1条回答
  • 2020-12-21 13:25

    You have several options. If you are using Guice, here is a very straightforward way to inject your implementation.

    If not, you can use a mix of factories and data provider:

    @Factory(dataProvider = "dp")
    public FactoryDataProviderSampleTest(StrategyInterface si) {
    }
    
    @DataProvider
    static public Object[][] dp() {
      return new Object[][] {
        new Object[] { new Strategy1Impl() },
        new Object[] { new Strategy2Impl() },
      };
    }
    
    0 讨论(0)
提交回复
热议问题