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

Fixture beforeAll runs when suite excluded via --exclude-categories #497

Closed
valencik opened this issue Mar 2, 2022 · 2 comments
Closed

Comments

@valencik
Copy link
Collaborator

valencik commented Mar 2, 2022

Reproduction: https://github.com/valencik/munit-fixture-suite-filtering

TLDR: The beforeAll method still runs on a Fixture defined in a suite that is excluded via junit Category.

I would like to use a reusable suite local fixture to setup some external state for some integration tests. However, when I filter/exclude all tests in the test suite with either .ignore or --exclude-categories the Fixture's beforeAll method is still called.

Of note, @munit.IgnoreSuite does successfully prevent the Fixture from running.

Reproduction README copy and pasted below:


This repo is a little reproduction of an munit issue.

A reusable Fixture's beforeAll method runs even when it's defining suite is excluded via --exclude-categories=.
Consider the following test file:

package example

import org.junit.experimental.categories.Category

class Slow extends munit.Tag("Slow")

@Category(Array(classOf[Slow]))
class MySuite extends munit.FunSuite {

  val myFixture = new Fixture[Unit]("myFixture") {
    def apply(): Unit = println("### myFixture apply() ###")

    override def beforeAll(): Unit = {
      println("### beforeAll is running ###")
    }

    override def afterAll(): Unit = {
      println("### afterAll is running ###")
    }
  }
  override def munitFixtures = List(myFixture)

  test("test1") {
    myFixture()
    assertEquals(1, 1)
  }

  test("test2") {
    myFixture()
    assertEquals(1, 1)
  }
}

Within an sbt shell,
test yields the following, as expected:

### beforeAll is running ###
### myFixture apply() ###
### myFixture apply() ###
### afterAll is running ###
example.MySuite:
  + test1 0.017s
  + test2 0.0s
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2

The test suite MySuite is annotated with a junit Category.
Which allows us to include or exclude whole test suites.
When we exclude MySuite the tests are skipped but the Fixture's beforeAll method still runs:

testOnly -- --exclude-categories=example.Slow yields:

### beforeAll is running ###
### afterAll is running ###
example.MySuite:
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
olafurpg added a commit to olafurpg/munit that referenced this issue Mar 5, 2022
Previously, MUnit loaded fixtures even for test suites that had no
tests. Now, we skip the entire suite if there are no tests to run.
@olafurpg
Copy link
Member

olafurpg commented Mar 5, 2022

Thank you for reporting! I'm able to reproduce and I opened a PR with a fix #499

@olafurpg
Copy link
Member

olafurpg commented Mar 5, 2022

I triggered a 1.0.0-M2 release with the fix, it may take a while to sync with Maven Central

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

No branches or pull requests

2 participants