Run all tests from *tests* folder

已回答

Hi!

I have some tests in the "main" folder so maven won't pick it up as unit test in the test phase.

My question is is it possible to have a run configuration in IDEA achieving a similar behavior?

Today if I run any pattern or package IDEA looks in both "main" and "test".

Thanks.

0

You can use Pattern - it will run tests that match the pattern in different directories.

Note that according to Maven standard layout the main directory is used for application sources/resources. If you are using Maven in project you should configure source sets in Maven configuration (e.g. using build section or additional Maven plugins) since IDE uses only it when configuring project structure, dependencies, compiler etc for the project.

0
Avatar
Permanently deleted user

Sorry, I don't really get how patterns will help me.

Let's say I have an org.mytest.WhateverTest in src/main and org.mytest.WhateverUnitTest in src/test.

If I understand correctly how pattern works in IDEA I can match a regex on fully qualified names of the classes. But this way I can't exclude WhateverTest unless I have a naming convention, am I right?

Maybe the title was misleading because the folder's name is test (without s) and the stars don't act as bold formatting.

0

Hello Viktor,

Please clarify what behaviour do you see when you right click on the test package and select "Run All tests"? Thanks

0
Avatar
Permanently deleted user

Hello Olga,

Test is not a package but a folder and if I right click there is no such option "Run all tests" only if I right click on the java folder inside the test folder.

What happens when I run all tests on the java folder inside test folder is that IDEA creates a run configuration to run all tests in package with no package name specified. As a result both in "main" and "test" folders all tests will be run which is not what I want.

Or if I turn it around, in the target folder the classes from the src/test folder will end up in target/test-classes. These are the ones which I want to run. The classes which I want to exclude are the classes in target/classes (built from src/main), which are also run by IDEA.

I hope it is clear now.

0

Viktor, 

It's not quite clear where is the test source root defined in your project, it possible can you please share the screenshot taken from your Project view pane showing the packages and directories structure. Thank you 

0
Avatar
Permanently deleted user

I rather created a dummy repo: https://github.com/karkusviktor/Example

0

Viktor,

Thank you for providing the sample, the both tests (under source root and test source root) in sample project are located in the same package, so run configuration results created for the package are expected.

Possible solution in this case can be either naming the tests differently so that the Pattern configuration can be created or moving one of the tests to the package with different name.

0
Avatar
Permanently deleted user

Then I rather use "mvn test" mainly which can distinguish between folders.

As a workaround I rather created a suite xml via reflection with the classes I need to overcome IDEA's handicap.

Thanks for your help.

0

I have a similar problem in RustRover and WebStorm.

Example repository: Puppeteer. All tests are in `test/` folder in the repository root. I want to right click on any folder (e.g. `test` or `test/src/`) and be able to run all tests in that folder and any of its subfolders.

ATM, I don’t see `Run all tests in $folder_name` in the context menu of any folder. I can see only `Run $test_filename` in the context menu of a test file.

Tested in RustRover 2024.3.2 and WebStorm 2024.3.1.1.

0

Rescaray there is currently no way to run all Mocha tests in a folder from the context menu. Please vote for WEB-39065 to get notified of any progress with this feature.

0

请先登录再写评论。