IntelliJ IDEA运行配置正则表达式问题:排除集成测试生效但前端测试未生效的求助
Why Your Regex Isn't Working in IntelliJ IDEA
First off, let's clarify: this isn't an IntelliJ limitation—it's a small oversight in how your regex accounts for fully qualified class names (which is what IntelliJ uses when matching test classes in run configurations).
The Root Cause
When you tested your regex ^(?!(.*IT$)|T[0-9]{2}).*$ in a regex tool, you were probably testing against just the class name (like T00_00_FrontendTest). But in IntelliJ, the regex matches against the full class name including the package (e.g., com.yourcompany.tests.T00_00_FrontendTest).
Your current regex checks if the string starts with T[0-9]{2}, but in a full class name, the start is the package (like com.yourcompany...), not the class name. So the negative lookahead for T[0-9]{2} never triggers for frontend tests—IntelliJ doesn't see the T00 at the start of the string, only later after the package dots.
The Fix: Update Your Regex
You need to adjust the regex to target the class name portion of the full qualified name (the part after the last dot). Here's a corrected version that handles both exclusion rules:
^(?!.*IT$)(?!.*\.T[0-9]{2}_[0-9]{2}_).*$
Let's break this down:
^(?!.*IT$): Keeps working as before—excludes any class whose full name ends withIT(your integration tests).(?!.*\.T[0-9]{2}_[0-9]{2}_): Adds a check to exclude any class where, somewhere in the full name, there's a dot followed byT+ 2 digits + underscore + 2 digits + underscore (matching your frontend test naming patternT00_00_NameOfTestClass).
How to Verify
Test this regex against full class names to confirm:
- ✅ Matches:
com.yourcompany.tests.MyUnitTest(valid unit test) - ❌ Excludes:
com.yourcompany.tests.MyIntegrationTestIT(integration test) - ❌ Excludes:
com.yourcompany.frontend.tests.T00_00_LoginTest(frontend test)
Applying in IntelliJ
- Open your Run/Debug Configurations.
- Select your JUnit configuration for unit tests.
- Under the "Test kind" dropdown, choose Pattern.
- Paste the corrected regex into the pattern field.
- Save the configuration and run your tests—both integration and frontend tests should now be excluded as expected.
内容的提问来源于stack exchange,提问作者Oliver

