Skip to content

Commit

Permalink
Fix #497 - don't load fixtures for empty test suites (#499)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olafurpg authored Mar 5, 2022
1 parent 9653a0e commit aa30ff9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 16.7.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.junit.experimental.categories

import scala.annotation.Annotation

class Category(classes: Array[Class[_]]) extends Annotation
2 changes: 1 addition & 1 deletion munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
}

private def runAll(notifier: RunNotifier): Future[Unit] = {
if (PlatformCompat.isIgnoreSuite(cls)) {
if (PlatformCompat.isIgnoreSuite(cls) || munitTests.isEmpty) {
val description = getDescription()
notifier.fireTestIgnored(description)
return Future.successful(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Issue285FrameworkSuite extends FunSuite {
}
test("issue-285-fail") {
val promise = Promise[Unit]()
PlatformCompat.setTimeout(20) {
PlatformCompat.setTimeout(40) {
promise.trySuccess(())
}
promise.future
Expand Down
44 changes: 44 additions & 0 deletions tests/shared/src/main/scala/munit/Issue497FrameworkSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package munit

import org.junit.experimental.categories.Category

class Slow extends Tag("Slow")

@Category(Array(classOf[Slow]))
class Issue497FrameworkSuite extends FunSuite {
def println(msg: String): Unit = TestingConsole.out.println(msg)
val myFixture: Fixture[Unit] = 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[Fixture[Unit]] = List(myFixture)

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

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

object Issue497FrameworkSuite
extends FrameworkTest(
classOf[Issue497FrameworkSuite],
"""|munit.Issue497FrameworkSuite:
|""".stripMargin,
arguments = Array("--exclude-categories=munit.Slow"),
tags = Set(
OnlyJVM
),
format = StdoutFormat
)
1 change: 1 addition & 0 deletions tests/shared/src/test/scala/munit/FrameworkSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FrameworkSuite extends BaseFrameworkSuite {
AssertionsFrameworkSuite,
Issue179FrameworkSuite,
Issue285FrameworkSuite,
Issue497FrameworkSuite,
ScalaCheckExceptionFrameworkSuite,
BoxedFrameworkSuite
)
Expand Down

0 comments on commit aa30ff9

Please sign in to comment.