-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Since multiple @RunWith impossible, a static way to initialize the Runner is needed #79
Comments
Hi @sxilderik, in the moment I have no idea how this should work as JUnit is very inflexible at this point. But maybe you can do the same as we did with https://github.com/TNG/junit-dataprovider/wiki/Tips-and-Tricks Would be great if you could test that out and if you like also add a documentation for it. If you encounter any problem, don't hesitate to ask :-) Cheers, |
Hi Everyone, I have a JUNIT Test “MyTest” as below which uses @RunWith and SpringJUnit4ClassRunner as below: @RunWith(SpringJUnit4ClassRunner.class)
@test } The test was running fine but I had lots of hardcoded data (Invoices) in @before and hence I thought of using TestNG DataProvider to suppy data and while searching this came across this JUNIT Data Provider. I downloaded the dependencies for JUNIT DataProvider and written a separate class JunitDataProvider as below: @RunWith(DataProviderRunner.class)
} Now the issue is If I run my test with @RunWith(SpringJUnit4ClassRunner.class) I get below exception If I run my test with @RunWith(DataProviderRunner.class) it gives java.lang.NullPointerException in @before Method, below Line. int updatedRows = dataCook.cookTestData(invoices); |
Hi @Vivek-Malhotra, as already mentioned before, please see where a detailed guide is provided for using JUnit dataprovider (= Does this help? Cheers, P.S.: As JUnit Lambda (= JUnit 5) is a lot more flexible we have to wait for this to get it run using multiple extensions... Am 28. Juli 2016 16:58:02 MESZ, schrieb Vivek-Malhotra [email protected]:
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet. |
Thanks @aaschmid for your reply. I looked at the solution. It looks like in my TestClass I can extend SpringJUnit4ClassRunner class as shown below. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; However the issue is that my Test Class Already extends from some other class and hence I don't know how I can extend from SpringJUnit4ClassRunner as well. public class LasXXXTest extends LasBaseTest { |
Hi @Vivek-Malhotra, you don't need to extend the test class but annotate it with Cheers, |
Thanks @aaschmid As you mentioned, I have downloaded DataProviderRunner.java and tried to do the below workarounds which you have mentioned. However in DataProviderRunner.java, I can't find any statement.evaluate() or any other functions you mentioned The body of this class is identical with DataProviderRunner.java but needs a small hack to work. Without any modification a NullPointerException is thrown in The simplest solution is to comment out statement.evaluate();, which obviously breaks the @BeforeClass annotation. Alternatively, replacing the function above by the following two functions also fixes the issue without breaking @BeforeClass. |
Hi @aaschmid Some progress made. Now after creating a DataProviderRunner and Creating a dataProvider in JunitDataProvider.java I am getting below error: java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available. @RunWith(DataProviderRunnerWithSpring.class) @test } |
Hello @aaschmid 1, Created a JunitDataProvider class with test data @test
java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.
Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findAllMergedAnnotations(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/util/Set; Process finished with exit code -1 Do you know what could be the isssue here. I think something in POM is creating this issue. |
Hi @Vivek-Malhotra, sorry the tips and tricks page was outdated a bit as the adjustments where not necessary if you use v.1.10.4 or newer. I have updated the documentation and just added an example to the integration tests, see https://github.com/TNG/junit-dataprovider/tree/spring-acceptance-test/src/integTest/java/com/tngtech/test/java/junit/dataprovider/spring. Does this help? Cheers, P.S.: This does not use Spring Boot but should be also runnable within a Spring Boot application. |
Oh, haven't overseen your latest comment @Vivek-Malhotra. I guess you are correct, this is a problem in your POM i.e. it is caused by a dependency version conflict, e.g. some spring-boot version which does not match the corresponding spring-core library... Cheers, |
@sxilderik Are your problems solved using the tips and tricks page? Such that I can close this issue in the near future? |
Thanks @aaschmid It works for me now. There were some issues with POM which I managed to rectify and it worked now. I can access test data from Data Provider in my Test class like below: Just one last question: Can we use this Dataprovider during test setup in @before ?? @RunWith(DataProviderRunnerWithSpring.class) **@before
}** If I try to use it in @before class, I get error like below: Many Thanks once again. |
Hi @Vivek-Malhotra, |
Thanks @aaschmid Regarding the use case in @before I am not sure whether that is correct as I am pretty new to spring. What I though from my previous experience on other Test Frameworks, I used to do any prerequisites for a test in a setup script. Similarly, there should be an option to use test data from test data provider in @before. For e.g. I have a use case, where my Test Need some XML Invoices which are coming from a Mock. I am starting the Mock in @before and would like to pass the test data which my Mock needs in @before. Then in @before I am hosting the mock with the XML invoices from Test Data Provider. Then I am adding some Test Data in some DB based on the Data from Test Data provider. All this is prerequisite for my test to run. Since it doesn't work in @before. I am simply doing in in @test at the moment and that's fine. However, it would have been nice to have similar feature in @before. What are your views on this? |
See #82 to follow up on this |
Since no more response on this, I will close the issue |
Hi @alexandroid, thanks for the hint. I recently updated the referenced branch to the new master with containing subprojects now and overlooked that it was referenced in the "Tips and Tricks" page. I fixed the links in the documentation. If you have any further questions or issues, please don't hesitate to create an issue or add a comment here :-) Cheers, |
Instructions above did not work for me, they seem outdated or I did something wrong. |
Thanks for this comment. Do you have an exception message or compile error for me? Which versions do you use? |
I think I used "junit-dataprovider v1.10.0" as mentioned and not all imports in https://github.com/TNG/junit-dataprovider/blob/master/junit4/src/main/java/com/tngtech/java/junit/dataprovider/DataProviderRunner.java got resolved. I quickly moved on to other instructions so maybe there was something I did not read. For example I just saw mentioned that I should have "cdi-unit v3.1.3" as a dependency and I did not have that dependency. Since the instructions on the link I posted work well I did not dig into the problems I was having. Version of junit-dataprovider used on the link is also more recent "1.13.1". |
Hello
I'm using @RunWith(Arquillian.class) and I'd like to @DataProvide my tests there too.
Since there is no way to say @RunWith twice, how can I use @dataProvider in my Arquillian test class ?
Is there a way to statically initialize or do whatever mojo is needed to mimic the @RunWith(DataProviderRunner.class) ?
@before
public void init() {
DataProviderRunner.doTheMagic().
}
The text was updated successfully, but these errors were encountered: