Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @Ignore to be used on test classes without BUILD file change #4073

Closed
wants to merge 1 commit into from

Conversation

snowp
Copy link
Contributor

@snowp snowp commented Nov 12, 2017

Currently a test class annotated with @Ignore will cause the test runner to fail with

    Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite
        at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53)

This happens because a test class with @Ignore will have 0 tests in the Request created from the test class.

This change treats classes with no tests (e.g. no @Test annotations or @Ignore at class level) as an empty test suite. The main motivation behind this is allowing an entire test class to be ignored (e.g. to quickly deal with a flaky test) without having to modify the BUILD file. This is desirable in order to reduce the likelihood that a developer forgets to update the BUILD file when removing the @Ignore annotation.

Not sure if this should be flagged off or not? I don't imagine anyone relying on the check that I'm removing, but I am making it a bit more permissive so might be a good idea?

@bazel-io
Copy link
Member

Can one of the admins verify this patch?

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

Currently a test class annotated with `@Ignore` will cause the test
runner to fail with

```
Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite
	at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53)
```

This change treats classes with no tests (either no @test annotations or
@ignore at class level) as an empty test suite. The main motivation
behind this is allowing an entire test class to be ignored (e.g. to
quickly deal with a flaky test) without having to modify the BUILD file.
This is desirable in order to reduce the likelihood that a developer
forgets to update the BUILD file when removing the `@Ignore` annotation.
@snowp
Copy link
Contributor Author

snowp commented Nov 12, 2017

Had some extraneous commits that got dragged in and messed up the googlebot check, but I cleaned that up

@damienmg
Copy link
Contributor

@googlebot: ping

@damienmg
Copy link
Contributor

The problem with the CLA bot: the email you used to register with the CLA is the one at Square. Since you are covered by the Corporate CLA you should use that one instead.

@snowp
Copy link
Contributor Author

snowp commented Nov 13, 2017

Ah, that makes sense. I'll reauthor the commit

@@ -50,8 +50,9 @@ public JUnit4TestModelBuilder(Request request, @TopLevelSuite String suiteName,
public TestSuiteModel get() {
Description root = request.getRunner().getDescription();
if (!root.isSuite()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment explaining the logic of the if branches?

@@ -50,8 +50,9 @@ public JUnit4TestModelBuilder(Request request, @TopLevelSuite String suiteName,
public TestSuiteModel get() {
Description root = request.getRunner().getDescription();
if (!root.isSuite()) {
throw new IllegalArgumentException("Top test must be a suite");
return builder.build(suiteName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method exist? I cannot find it in the TestSuiteModel

@StephenAmar
Copy link

What's the status?

@snowp
Copy link
Contributor Author

snowp commented Dec 12, 2017

@StephenAmar I haven't had the bandwidth to see this one through and probably won't for another few weeks. Feel free to take this over or make your own fix based on mine if this issue is more urgent for you.

StephenAmar pushed a commit to StephenAmar/bazel that referenced this pull request Dec 13, 2017
Currently a test class annotated with `@Ignore` will cause the test
runner to fail with

```
Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite
	at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53)
```

This change treats classes with no tests (either no @test annotations or
@ignore at class level) as an empty test suite. The main motivation
behind this is allowing an entire test class to be ignored (e.g. to
quickly deal with a flaky test) without having to modify the BUILD file.
This is desirable in order to reduce the likelihood that a developer
forgets to update the BUILD file when removing the `@Ignore` annotation.

This pull request overrides the previous pull request
bazelbuild#4073
@StephenAmar
Copy link

Done with #4293

@snowp
Copy link
Contributor Author

snowp commented Dec 13, 2017

Thanks!

@snowp snowp closed this Dec 13, 2017
bazel-io pushed a commit that referenced this pull request Mar 13, 2018
Currently a test class annotated with `@Ignore` will cause the test
runner to fail with

```
Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite
	at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53)
```

This change treats classes with no tests (either no @test annotations or
@ignore at class level) as an empty test suite. The main motivation
behind this is allowing an entire test class to be ignored (e.g. to
quickly deal with a flaky test) without having to modify the BUILD file.
This is desirable in order to reduce the likelihood that a developer
forgets to update the BUILD file when removing the `@Ignore` annotation.

This pull request overrides the previous pull request
#4073

Closes #4293.

PiperOrigin-RevId: 188850828
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this pull request Sep 4, 2022
    Currently a test class annotated with `@Ignore` will cause the test
    runner to fail with

    ```
    Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite
            at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53)
    ```

    This change treats classes with no tests (either no @test annotations or
    @ignore at class level) as an empty test suite. The main motivation
    behind this is allowing an entire test class to be ignored (e.g. to
    quickly deal with a flaky test) without having to modify the BUILD file.
    This is desirable in order to reduce the likelihood that a developer
    forgets to update the BUILD file when removing the `@Ignore` annotation.

    This pull request overrides the previous pull request
    bazelbuild/bazel#4073

    Closes #4293.

    PiperOrigin-RevId: 188850828
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants