Closed aaschmid closed 8 years ago
Hi @Vivek-Malhotra,
I think it is possible to implement if I understand you corrently. However, as I am now thinking more detailed about it, I have some doubt about the usefullness. I am currently not convinced what the benefits would be because it would cause some additional boiler plate code to add a second method for every test case annotated e.g. with @BeforeDataProvider("dataProviderName")
. And as you can put the setup stuff into your @Test
method where it also occurs only once, you already safe a lot of duplicated code ...
Do you understand what I mean? (You already implemented it like that :-) )
Cheers, Andreas
P.S.: What I already discussed some time ago is a method which is called before the first method of a certain dataprovider and after the last method of the same dataprovider to run...
Hi @aaschmid Agreed on your point. I can have my setup inside @Test where I can provide test data from Data Provider.
Why I thought it would be good to add Test Data in @Before was in case I have several test methods in my class which needs same test data, I have to use this data provider in every test method (@Test). It would have been good if I provide Test Data in @Before and then all my tests use the same data.
But anyways its not that important as currently my purpose is solved and I am not sure if using test data in @Before is a correct approach as you mentioned about boiler plate code.
Also, you mentioned about @BeforeDataProvider("dataProviderName"). What is that. Is this some additional annotation provided by your data provider?
Thanks, Vivek
Hi @Vivek-Malhotra,
yes this is the correct use case to add the test data for every test case in @Before
. The @BeforeDataProvider("dataProviderName")
was just a name suggestion for your idea. The more I think about it, I think it would be a good idea to try to create something like @BeforeDataProvider("dataProviderName")
and @AfterDataProvider("dataProviderName")
which is executed before the first test using the dataprovider with name "dataProviderName" and once after the last test ... (without being able to access the dataprovider data - at least for a first version).
Would that make sense to you? Do you see any benefit for that?
Cheers, Andreas
I implemented already some part of it because I was curious about if this would work. And yes, it would work but due to the bad extensibility of JUnit it is a bit hacky ...
Anybody would like to have that feature?
Hi @aaschmid ,
This is really great that you already tried to make it work. That’s super fast I can say
I am not sure how useful it would be to put these efforts against what we already have. Some of the use cases which I can think of (based on my lame experience with Junit) are as below:
Please let me know what you think:
Use Case I: I have one DataProvider Class having One DataProvider for One Test Class having n Number of Tests
One Data Provider Class - JunitDataProvider
_@Dataprovider Public static Object [][] testDataForMyTestA(){ }_
One Spring Junit Test Class – With n Tests
@RunWith(DataProviderRunnerWithSpring.class) @SpringApplicationConfiguration(TestConfiguration.class) public class MyTestA extends MyBaseTest {
@Test @UseDataProvider(value = " testDataForMyTestA ", location = JunitDataProvider.class) public void testMethod1(String invoice1, String invoice2) throws Exception { }
@Test @UseDataProvider(value = " testDataForMyTestA ", location = JunitDataProvider.class) public void testMethod2(String invoice1, String invoice2) throws Exception { } }
**Use Case II: I have one DataProvider Class having n DataProviders for One Test Class having n Number of Tests
One Data Provider Class having n DataProviders - JunitDataProvider**
@Dataprovider Public static Object [][] testDataForMyTestA(){ }
@Dataprovider Public static Object [][] testDataForMyTestB(){ }
One Spring Junit Test Class – With n Tests
@RunWith(DataProviderRunnerWithSpring.class) @SpringApplicationConfiguration(TestConfiguration.class) public class MyTestA extends MyBaseTest {
@Test @UseDataProvider(value = " testDataForMyTestA ", location = JunitDataProvider.class) public void testMethod1(String invoice1, String invoice2) throws Exception { }
@Test @UseDataProvider(value = " testDataForMyTestB ", location = JunitDataProvider.class) public void testMethod2(String invoice1, String invoice2) throws Exception { } }
Use Case III: I have one DataProvider Class having n DataProviders for Different Test Classes
One Data Provider Class having n DataProviders - JunitDataProvider
@Dataprovider Public static Object [][] testDataForMyTestA(){ }
@Dataprovider Public static Object [][] testDataForMyTestB(){ }
Multiple Spring Junit Test Class consuming corresponding DataProviders
@RunWith(DataProviderRunnerWithSpring.class) @SpringApplicationConfiguration(TestConfiguration.class) public class MyTestA extends MyBaseTest {
@Test @UseDataProvider(value = " testDataForMyTestA ", location = JunitDataProvider.class) public void testMethod1(String invoice1, String invoice2) throws Exception { } }
@RunWith(DataProviderRunnerWithSpring.class) @SpringApplicationConfiguration(TestConfiguration.class) public class MyTestB extends MyBaseTest {
@Test @UseDataProvider(value = " testDataForMyTestB ", location = JunitDataProvider.class) public void testMethod1(String invoice1, String invoice2) throws Exception { } }
Regards Vivek Malhotra
Hi @Vivek-Malhotra, I am sorry but I am not sure what that has to do with the @BeforeDataProvider
and / or @AfterDataProvider
...
While thinking in more depth about it, it makes no sence to have a @BeforeDataProvider("dataProviderName")
and @AfterDataProvider("dataProviderName")
because
@BeforeClass
and @AfterClass
with some exclusively used static fieldsSo I will close this issue
Taken from #79, asked by @Vivek-Malhotra: