JUnit 4 @Test annotation not taken into account when filtering by tags
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
When I try to run tests with tag filtering, only those marked with @Test from JUnit 5 are executed but not those marked with @Test from JUnit 4.
The point is that if the filtering expression is "!slow", it actually executes tests without the tag "slow" regardless which @Test annotation is used. But when I filter with the expression "slow", tests with this tag won't be executed if they have the @Test from JUnit 4.
I know I could change to the new annotation when adding a tag but it would be nice not to have to do that for the tests I already have.
I have this imported into my pom
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
And the test I am trying to run is
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Tag;
public class Test {
@org.junit.Test
@Tag("slow")
public void test() {
assertTrue(true);
}
}
java junit junit4 junit5
add a comment |
When I try to run tests with tag filtering, only those marked with @Test from JUnit 5 are executed but not those marked with @Test from JUnit 4.
The point is that if the filtering expression is "!slow", it actually executes tests without the tag "slow" regardless which @Test annotation is used. But when I filter with the expression "slow", tests with this tag won't be executed if they have the @Test from JUnit 4.
I know I could change to the new annotation when adding a tag but it would be nice not to have to do that for the tests I already have.
I have this imported into my pom
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
And the test I am trying to run is
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Tag;
public class Test {
@org.junit.Test
@Tag("slow")
public void test() {
assertTrue(true);
}
}
java junit junit4 junit5
1
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59
add a comment |
When I try to run tests with tag filtering, only those marked with @Test from JUnit 5 are executed but not those marked with @Test from JUnit 4.
The point is that if the filtering expression is "!slow", it actually executes tests without the tag "slow" regardless which @Test annotation is used. But when I filter with the expression "slow", tests with this tag won't be executed if they have the @Test from JUnit 4.
I know I could change to the new annotation when adding a tag but it would be nice not to have to do that for the tests I already have.
I have this imported into my pom
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
And the test I am trying to run is
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Tag;
public class Test {
@org.junit.Test
@Tag("slow")
public void test() {
assertTrue(true);
}
}
java junit junit4 junit5
When I try to run tests with tag filtering, only those marked with @Test from JUnit 5 are executed but not those marked with @Test from JUnit 4.
The point is that if the filtering expression is "!slow", it actually executes tests without the tag "slow" regardless which @Test annotation is used. But when I filter with the expression "slow", tests with this tag won't be executed if they have the @Test from JUnit 4.
I know I could change to the new annotation when adding a tag but it would be nice not to have to do that for the tests I already have.
I have this imported into my pom
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
And the test I am trying to run is
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Tag;
public class Test {
@org.junit.Test
@Tag("slow")
public void test() {
assertTrue(true);
}
}
java junit junit4 junit5
java junit junit4 junit5
edited Jan 3 at 11:59
Roland Weisleder
3,90332340
3,90332340
asked Jan 3 at 8:19
JavierJavier
193
193
1
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59
add a comment |
1
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59
1
1
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59
add a comment |
1 Answer
1
active
oldest
votes
You can't mix JUnit 4 and JUnit 5 annotations in the same test. So your approach will not work. A solution might be to migrate these tagged tests to JUnit 5.
Background: The JUnit Platform uses different test engines to discover and execute tests. The junit-vintage-engine can handle tests written against the JUnit 4 API, where test methods are annotated with @org.junit.Test
. The junit-jupiter-engine can handle tests written against the JUnit Jupiter API (commonly known as JUnit 5), where test methods are annotated with @org.junit.jupiter.api.Test
. Each engine only has knowlegde about their discovered test methods. The junit-vintage-engine doesn't have any behaviour for JUnit Jupiter annotations, so these annotations are simply ignored.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018589%2fjunit-4-test-annotation-not-taken-into-account-when-filtering-by-tags%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't mix JUnit 4 and JUnit 5 annotations in the same test. So your approach will not work. A solution might be to migrate these tagged tests to JUnit 5.
Background: The JUnit Platform uses different test engines to discover and execute tests. The junit-vintage-engine can handle tests written against the JUnit 4 API, where test methods are annotated with @org.junit.Test
. The junit-jupiter-engine can handle tests written against the JUnit Jupiter API (commonly known as JUnit 5), where test methods are annotated with @org.junit.jupiter.api.Test
. Each engine only has knowlegde about their discovered test methods. The junit-vintage-engine doesn't have any behaviour for JUnit Jupiter annotations, so these annotations are simply ignored.
add a comment |
You can't mix JUnit 4 and JUnit 5 annotations in the same test. So your approach will not work. A solution might be to migrate these tagged tests to JUnit 5.
Background: The JUnit Platform uses different test engines to discover and execute tests. The junit-vintage-engine can handle tests written against the JUnit 4 API, where test methods are annotated with @org.junit.Test
. The junit-jupiter-engine can handle tests written against the JUnit Jupiter API (commonly known as JUnit 5), where test methods are annotated with @org.junit.jupiter.api.Test
. Each engine only has knowlegde about their discovered test methods. The junit-vintage-engine doesn't have any behaviour for JUnit Jupiter annotations, so these annotations are simply ignored.
add a comment |
You can't mix JUnit 4 and JUnit 5 annotations in the same test. So your approach will not work. A solution might be to migrate these tagged tests to JUnit 5.
Background: The JUnit Platform uses different test engines to discover and execute tests. The junit-vintage-engine can handle tests written against the JUnit 4 API, where test methods are annotated with @org.junit.Test
. The junit-jupiter-engine can handle tests written against the JUnit Jupiter API (commonly known as JUnit 5), where test methods are annotated with @org.junit.jupiter.api.Test
. Each engine only has knowlegde about their discovered test methods. The junit-vintage-engine doesn't have any behaviour for JUnit Jupiter annotations, so these annotations are simply ignored.
You can't mix JUnit 4 and JUnit 5 annotations in the same test. So your approach will not work. A solution might be to migrate these tagged tests to JUnit 5.
Background: The JUnit Platform uses different test engines to discover and execute tests. The junit-vintage-engine can handle tests written against the JUnit 4 API, where test methods are annotated with @org.junit.Test
. The junit-jupiter-engine can handle tests written against the JUnit Jupiter API (commonly known as JUnit 5), where test methods are annotated with @org.junit.jupiter.api.Test
. Each engine only has knowlegde about their discovered test methods. The junit-vintage-engine doesn't have any behaviour for JUnit Jupiter annotations, so these annotations are simply ignored.
answered Jan 3 at 11:10
Roland WeislederRoland Weisleder
3,90332340
3,90332340
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018589%2fjunit-4-test-annotation-not-taken-into-account-when-filtering-by-tags%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
you mean you have several versions of junit in a single project? why?
– Stultuske
Jan 3 at 8:21
Because I have added JUnit 5 today and @Test annotations are in different packages. That means I would have to go to every single test class to change the import statement. That's something I don't want to do.
– Javier
Jan 3 at 10:07
IMHO it's okay to have JUnit 4 and 5 in the same project, when 5 was added to an existing project and you don't want to migrate all test classes at once.
– Roland Weisleder
Jan 3 at 10:59