[ 
https://issues.apache.org/jira/browse/SUREFIRE-1676?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16887188#comment-16887188
 ] 

Tibor Digana edited comment on SUREFIRE-1676 at 7/17/19 3:57 PM:
-----------------------------------------------------------------

Let's suppose simple conditions where the forked JVM is only one and there's no 
re-run.
In this case the JVM and junit4 provider calls {{new JUnitCore()}} for each 
class separately.
In this case with junit47 provider there is one call of {{new JUnitCore()}} 
which takes all test classes.
We as Surefire do nothing with the classes. The JUnitCore does.

This is how it works.

Back to your question.
Yes, then the behavior would be as you have described.

Simly the reason is that the framework {{JUnitCore}} instantiate classes to 
objects and there is the place where the static context is executed. But as I 
have said, it's the JUnit library which instantiates the objects, we don't.

We only control the granularity of test classes, where we call JUnit for one 
(provider 4) or for all bunch of classes (4.7).

Did I answer your question?


was (Author: tibor17):
Let's suppose simple conditions the forked JVM is only one.
In this case the JVM and junit4 provider calls {{new JUnitCore()}} for each 
class separately.
In this case with junit47 provider there is one call of {{new JUnitCore()}} 
which takes all test classes.
We as Surefire do nothing with the classes. The JUnitCore does.

This is how it works.

Back to your question.
Yes, then the behavior would be as you have described.

Simly the reason is that the framework {{JUnitCore}} instantiate classes to 
objects and there is the place where the static context is executed. But as I 
have said, it's the JUnit library which instantiates the objects, we don't.

We only control the granularity of test classes, where we call JUnit for one 
(provider 4) or for all bunch of classes (4.7).

Did I answer your question?

> surefire-junit47 is not running JUnit4 tests
> --------------------------------------------
>
>                 Key: SUREFIRE-1676
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1676
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>    Affects Versions: 3.0.0-M3
>         Environment: Windows 10 and Centos 7 behave the same.
> java 1.8.161
>            Reporter: Bobby Erwin
>            Priority: Major
>         Attachments: mvn -X output2.txt, mvn-dependency-tree.log, 
> v15-effective-pom-01.xml
>
>
> In a maven project with lots of JUnit 4 tests, surefire-junit47 is not 
> executing the tests.
> There are no testng tests in this project, and there is no testng in the pom. 
> But this project has a dependency on another project that does have testng in 
> the pom.  You can see it import testng in the mvn -X output, attached.  
> With testng on the classpath, surefire tries to execute tests through testng. 
> So we're configuring our test execution based on this page: 
> https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
> For reference sake, here is the documentation I'm working 
> from:[https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html]
> Curiously enough, it appears to find the test classes, but doesn't execute 
> the methods.  That is, if processes all the static fields and @Parameterized 
> methods, but it doesn't execute any @Test methods.
> Here are a couple of pom configurations that show the problem.
> Given this test class organization:
> {code:java}
> - src/main/test/
>    - com.mycomp.qc.core.account
>      - CopyAccountTests.java
>      - CreateAccountTests.java
>      - DeleteAccountTests.java
>      - ListAccountTests.java
>      - ReadAccountTests.java
>      - UpdateAccountTests.java
>    - com.mycomp.qc.core.product
>      - CopyProductTests.java
>      - CreateProductTests.java
>      - DeleteProductTests.java
>      - ListProductTests.java
>      - ReadProductTests.java
>      - UpdateProductTests.java
>    - ..... and 300 more packages .....{code}
>  
> And given this test class structure:
> {code:java}
> package com.mycomp.qc.core.account;
> import org.junit.Assert;
> import org.junit.Test;
> .... and more ....
> public class CopyAccountTests {
>     @Test
>     public void copyAccount1() {
>         Assert.assertTrue("pass", true);
>     }
>     @Test
>     public void copyAccount2() {
>         Assert.assertTrue("fail", false);
>     }
> .... and more ....
> }{code}
>  
> *pom config 1: Specifically include Account tests, by pattern*
> Runs all the Account tests, just as the documentation indicates.
> {code:xml}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-surefire-plugin</artifactId>
>     <version>${surefire.version}</version>
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.maven.surefire</groupId>
>             <artifactId>surefire-junit47</artifactId>
>             <version>${surefire.version}</version>
>         </dependency>
>     </dependencies>
>     <configuration>
>         <testFailureIgnore>true</testFailureIgnore>
>         <includes>
>             <include>*Account*</include>
>         </includes>
>         <threadCount>1</threadCount>
>     </configuration>
>     <executions>
>         <execution>
>             <id>default-test</id>
>             <phase>test</phase>
>             <goals>
>                 <goal>test</goal>
>             </goals>
>         </execution>
>     </executions>
> </plugin>
> {code}
> *pom config 2: Specifically include Account tests, by pattern*
> Runs all the Account and Product tests, just as the documentation indicates.
> {code:xml}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-surefire-plugin</artifactId>
>     <version>${surefire.version}</version>
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.maven.surefire</groupId>
>             <artifactId>surefire-junit47</artifactId>
>             <version>${surefire.version}</version>
>         </dependency>
>     </dependencies>
>     <configuration>
>         <testFailureIgnore>true</testFailureIgnore>
>         <includes>
>             <include>*Account*</include>
>             <include>*Product*</include>
>         </includes>
>         <threadCount>1</threadCount>
>     </configuration>
>     <executions>
>         <execution>
>             <id>default-test</id>
>             <phase>test</phase>
>             <goals>
>                 <goal>test</goal>
>             </goals>
>         </execution>
>     </executions>
> </plugin>
> {code}
> *pom config 3: Include all tests, based on default surefire*
> Finds and initializes test classes, but does not execute any @Test methods.
> {code:xml}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-surefire-plugin</artifactId>
>     <version>${surefire.version}</version>
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.maven.surefire</groupId>
>             <artifactId>surefire-junit47</artifactId>
>             <version>${surefire.version}</version>
>         </dependency>
>     </dependencies>
>     <configuration>
>         <testFailureIgnore>true</testFailureIgnore>
>         <threadCount>1</threadCount>
>     </configuration>
>     <executions>
>         <execution>
>             <id>default-test</id>
>             <phase>test</phase>
>             <goals>
>                 <goal>test</goal>
>             </goals>
>         </execution>
>     </executions>
> </plugin>
> {code}
> *pom config 4: Include all tests, by pattern*
> Finds and initializes test classes, but does not execute any @Test methods.
> {code:xml}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-surefire-plugin</artifactId>
>     <version>${surefire.version}</version>
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.maven.surefire</groupId>
>             <artifactId>surefire-junit47</artifactId>
>             <version>${surefire.version}</version>
>         </dependency>
>     </dependencies>
>     <configuration>
>         <testFailureIgnore>true</testFailureIgnore>
>         <includes>
>             <include>*Test*</include>
>         </includes>
>         <threadCount>1</threadCount>
>     </configuration>
>     <executions>
>         <execution>
>             <id>default-test</id>
>             <phase>test</phase>
>             <goals>
>                 <goal>test</goal>
>             </goals>
>         </execution>
>     </executions>
> </plugin>
> {code}
> *What I've tried:*
> # Obviously, from the examples, I've tried different include patterns in the 
> pom. See the results outlined above.
> # Configured a new project, with all the same imports and just a few small 
> tests. All the include patterns above behaved as outlined in the 
> documentation.
> # Switched the surefire provider to surefire-junit4. This, in fact, executed 
> all tests, but we ran into other problems.
> # Ran mvn -X, mainly to look for testng problems, based on this answer: 
> Surefire is not picking up Junit 4 tests.
> # mvn -X showed that the default maven-resources-plugin pulls in junit 3.8.x, 
> which the doc says might cause problems. Updated resources to 3.1.0, but it 
> didn't fix my problem.
> *mvn -X output*
> attached



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to