TNG / junit-dataprovider

A TestNG like dataprovider runner for JUnit with many additional features
Apache License 2.0
246 stars 164 forks source link

Unable to run specific test using mvn commandline #111

Closed praveenc79 closed 6 years ago

praveenc79 commented 6 years ago

Overview

DataProviderRunnerWithSpring does not seem to support selectively running test from a testclass.

For example, In my project I have test - call TestClass and a specific test call test 1 @RunWith(DataProviderRunnerWithSpring.class) @ContextConfiguration(classes = IntegrationTestConfiguration.class) public class TestClass {

@UseDataProvider(value = TestDataProvider.USER, location = TestDataProvider.class) @Test public void test1(String userId) { .... }

@Test public void test2() { .... } }

Now if I run test as follows (using sure-fire plugin):--

mvn -Dtest=TestClass#test1 test

It does not pickup test1

mvn -Dtest=TestClass#test2 test

will work absolutely fine

Do you have any thoughts on this? Is this a new feature request ?

aaschmid commented 6 years ago

Hi @praveenc79,

thanks for your issue. Unfortunately, I cannot reproduce the issue. Therefore some questions:

Use Maven (v3.5.2 with surefire-plugin v2.17) on branch issue111-single-dataprovider-test-mvn-cmd-line from folder junit4 with a zsh:

# works without Spring
mvn -Dtest=\*JavaAcceptanceTest#testAddWithoutDataProvider clean test
mvn -Dtest=\*JavaAcceptanceTest#testIsEmptyString clean test
mvn -Dtest=\*JavaAcceptanceTest#testIsEmptyString\* clean test

# works with Spring
mvn -Dtest=\*SpringAcceptanceTest#testCreateGreetingDataProvider clean test
mvn -Dtest=\*SpringAcceptanceTest#testCreateGreetingNoDataProvider clean test
mvn -Dtest=\*SpringAcceptanceTest#testCreateGreeting\* clean test

In comparision use Gradle (v4.6) from repoistory root folder:

# does not work without Spring
./gradlew junit4:integTest --tests \*JavaAcceptanceTest.testIsEmptyString

# does not work with Spring
./gradlew junit4:integTest --tests \*SpringAcceptanceTest#testCreateGreetingDataProvider

# works without Spring
./gradlew junit4:integTest --tests \*JavaAcceptanceTest.testAddWithoutDataProvider
./gradlew junit4:integTest --tests \*JavaAcceptanceTest.testIsEmptyString\*

# works with Spring
./gradlew junit4:integTest --tests \*SpringAcceptanceTest#testCreateGreetingNoDataProvider
./gradlew junit4:integTest --tests \*SpringAcceptanceTest#testCreateGreeting\*
praveenc79 commented 6 years ago

hi @aaschmid

Thanks for coming up with project and examples in that. I really appreciate that. And a big apologies to come back to you late on this as well unlike your amazingly prompt response. After cloning this project and running your example though the way I needed, I did reproduce the problem. So it might be how I need or I how I am using it. I only need to to run say one test (taking input parameter)and this is how I am trying -

mvn -Dtest=JavaAcceptanceTest#testIsEmptyString clean test

and here is output - [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.788 s [INFO] Finished at: 2018-05-22T12:18:48-07:00 [INFO] Final Memory: 21M/217M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project junit-dataprovider: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1] [ERROR]

Any suggestions?

Thanks a bunch in advance, Praveen

aaschmid commented 6 years ago

The problem is the missing \* before JavaAcceptanceTest such that the command must be

mvn -Dtest=\*JavaAcceptanceTest#testIsEmptyString clean test

Otherwise you can also use the full class name:

mvn -Dtest=DataProviderJavaAcceptanceTest#testIsEmptyString clean test

Better?

praveenc79 commented 6 years ago

You are absolutely correct @aaschmid !!! I was confused by the total number of tests being run with those. When I closely looked at the test it shows runs for various data set.

It does not work in our project though. I will continue to work on that.

praveenc79 commented 6 years ago

I am closing issue.

aaschmid commented 6 years ago

Thx @praveenc79. If you have any further questions or issues, don't hesitate to open an issue.