JUnit doesn't discover classes within a folder with --select-directory

975 Views Asked by At

I tried to run with junit5 with stand alone runner the following command: java -jar ex1/lib/junit-platform-console-standalone-1.6.0-M1.jar --select-directory="./ex1/test"

with the following hierarchy:

.
├── ex1
│   ├── lib
│   │   ├── apiguardian-api-1.1.0.jar
│   │   ├── junit-jupiter-api-5.6.0-M1.jar
│   │   ├── junit-platform-commons-1.6.0-M1.jar
│   │   ├── junit-platform-console-standalone-1.6.0-M1.jar
│   │   └── opentest4j-1.2.0.jar
│   ├── mavnat.iml
│   ├── out
│   │   ├── production
│   │   │   └── mavnat
│   │   │       ├── AVLTree$AVLNode.class
│   │   │       ├── AVLTree.class
│   │   │       ├── AVLTree$DeletionBalancer.class
│   │   │       ├── AVLTree$IAVLNode.class
│   │   │       ├── AVLTree$InsertionBalancer.class
│   │   │       ├── AVLTree$Rotations.class
│   │   │       └── TreePrinter.class
│   │   └── test
│   │       └── mavnat
│   │           ├── ActualAVLTree.class
│   │           ├── ActualAVLTree$IAVLNode.class
│   │           ├── AVLSanitizer.class
│   │           ├── AVLTreeTest.class
│   │           ├── AVLTreeTestExternal.class
│   │           ├── DeletionTest.class
│   │           ├── ExTester$10.class
│   │           ├── ExTester$11.class
│   │           ├── ExTester$12.class
│   │           ├── ExTester$13.class
│   │           ├── ExTester$14.class
│   │           ├── ExTester$1.class
│   │           ├── ExTester$2.class
│   │           ├── ExTester$3.class
│   │           ├── ExTester$4.class
│   │           ├── ExTester$5.class
│   │           ├── ExTester$6.class
│   │           ├── ExTester$7.class
│   │           ├── ExTester$8.class
│   │           ├── ExTester$9.class
│   │           ├── ExTester.class
│   │           ├── InsertionTest.class
│   │           ├── META-INF
│   │           │   └── mavnat.kotlin_module
│   │           ├── RotationsTest.class
│   │           ├── SplitTest.class
│   │           ├── SuccessStatus.class
│   │           ├── TesterUtils.class
│   │           ├── Tests.class
│   │           └── TestUtils.class
│   ├── pro-1.docx
│   ├── src
│   │   ├── AVLTree.java
│   │   └── TreePrinter.java
│   └── test
│       ├── AVLSanitizer.java
│       ├── AVLTreeTestExternal.java
│       ├── AVLTreeTest.java
│       ├── DeletionTest.java
│       ├── InsertionTest.java
│       ├── JoinTest.java
│       ├── RotationsTest.java
│       ├── SplitTest.java
│       └── TestUtils.java
└── ex2 

Unfortunately, it seems that Junit launcher doesn't discover the tests.

╷
├─ JUnit Jupiter ✔
└─ JUnit Vintage ✔

Test run finished after 29 ms
[         2 containers found      ]
[         0 containers skipped    ]
[         2 containers started    ]
[         0 containers aborted    ]
[         2 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]

Does anyone know why tests aren't found? I would expect all the tests to be run and get info about failed tests.

edit: verbose run:

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

Test plan execution started. Number of static tests: 0
╷
├─ JUnit Jupiter
└─ JUnit Jupiter finished after 7 ms.
├─ JUnit Vintage
└─ JUnit Vintage finished after 2 ms.
Test plan execution finished. Number of all tests: 0

Test run finished after 42 ms
[         2 containers found      ]
[         0 containers skipped    ]
[         2 containers started    ]
[         0 containers aborted    ]
[         2 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]
1

There are 1 best solutions below

2
Sormuras On

JUnit Jupiter (shipped with "JUnit 5") and JUnit Vintage (executes "JUnit 3+4" tests) don't support the --select-directory option offered by the JUnit Platform (part of "JUnit 5"). Both engines only support class-based test selection, which means that test classes must be available on the class or module path at runtime.

Using paths from your directory tree, this standalone command should work:

java
  -jar junit-platform-console-standalone-${VERSION}.jar
  --class-path ex1/out/test
  --class-path ex1/out/production
  --scan-class-path

Assuming that you compiled all sources within IntelliJ IDEA.

Here's a hint how to compile your production/tests sources on the command line: How to launch JUnit 5 (Platform) from the command line (without Maven/Gradle)?