I'm trying to write a regex to run all unit tests but not run integration tests. Unit tests are named FooTest
, integration tests are named BarIntegrationTest
, with "Foo" and "Bar" being variables. I found this article on how to do it and I have solved my problem. But, its solution is to use this regex:
(.(?!Integration))*Test
I don't understand why this regex doesn't suffice:
.*(?!Integration)Test
When I tried that second regex, my Integration tests were still run.
You're using a negative look ahead, but you want a negative look behind:
.*(?<!Integration)Test
Your regex is asserting that "Test" is not "Integration", which of course is always true.
.*(?!Integration)Test
This involves .*
eating up the whole string and then backtracking to match Test
.For exmaple if test string is Integration test
.*
eats up the whole string and then applies the looahead which passes as after Test
there is no integration
.
Once .*
backtracks to match t
from Test
it again applies lookahead but fails so proceeds and matches Test in similar way applying the lookahead at each step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With