package junit5
- Alphabetic
- Public
- Protected
Type Members
- trait AssertionsForJUnit extends VersionSpecificAssertionsForJUnit
Trait that contains ScalaTest's basic assertion methods, suitable for use with JUnit 5.
Trait that contains ScalaTest's basic assertion methods, suitable for use with JUnit 5.
The assertion methods provided in this trait look and behave exactly like the ones in
Assertions, except instead of throwingTestFailedExceptionthey throwJUnitTestFailedError, which extendsorg.opentest4j.AssertionFailedError.JUnit 3 (release 3.8 and earlier) distinguishes between failures and errors. If a test fails because of a failed assertion, that is considered a failure. If a test fails for any other reason, either the test code or the application being tested threw an unexpected exception, that is considered an error. The way JUnit 3 decides whether an exception represents a failure or error is that only thrown
junit.framework.AssertionFailedErrors are considered failures. Any other exception type is considered an error. The exception type thrown by the JUnit 3 assertion methods declared injunit.framework.Assert(such asassertEquals,assertTrue, andfail) is, therefore,AssertionFailedError.In JUnit 4,
junit.framework.AssertionFailedErrorwas made to extendjava.lang.AssertionError, and the distinction between failures and errors was essentially dropped. However, some tools that integrate with JUnit carry on this distinction, so even if you are using JUnit 4 you may want to use thisAssertionsForJUnittrait instead of plain-old ScalaTestAssertions.In JUnit 5,
org.opentest4j.AssertionFailedErroris used as test-related AssertionError instead. - class JUnitSuite extends JUnitSuiteLike
A suite of tests that can be run with either JUnit or ScalaTest.
A suite of tests that can be run with either JUnit or ScalaTest. This class allows you to write JUnit 5 tests with ScalaTest's more concise assertion syntax as well as JUnit's assertions (
assertEquals, etc.). You create tests by defining methods that are annotated withTest, and can create fixtures with methods annotated withBeforeandAfter. For example:import org.junit.jupiter.api.{BeforeEach, Test} import org.scalatestplus.junit5.JUnitSuite import scala.collection.mutable.ListBuffer
class TwoSuite extends JUnitSuite {
var sb: StringBuilder = _ var lb: ListBuffer[String] = _
@BeforeEach def initialize() { sb = new StringBuilder("ScalaTest is ") lb = new ListBuffer[String] }
@Test def verifyEasy() { sb.append("easy!") assert(sb.toString === "ScalaTest is easy!") assert(lb.isEmpty) lb += "sweet" }
@Test def verifyFun() { sb.append("fun!") assert(sb.toString === "ScalaTest is fun!") assert(lb.isEmpty) }
}This version of
JUnitSuitewas tested with JUnit version 5.10.Instances of this class are not thread safe.
- trait JUnitSuiteLike extends Suite with AssertionsForJUnit
Implementation trait for class
JUnitSuite, which represents a suite of tests that can be run with either JUnit 5 or ScalaTest.Implementation trait for class
JUnitSuite, which represents a suite of tests that can be run with either JUnit 5 or ScalaTest.JUnitSuiteis a class, not a trait, to minimize compile time given there is a slight compiler overhead to mixing in traits compared to extending classes. If you need to mix the behavior ofJUnitSuiteinto some other class, you can use this trait instead, because classJUnitSuitedoes nothing more than extend this trait.See the documentation of the class for a detailed overview of
JUnitSuite. - class JUnitTestFailedError extends AssertionFailedError with StackDepth with ModifiableMessage[JUnitTestFailedError] with PayloadField with ModifiablePayload[JUnitTestFailedError]
Exception that indicates a test failed in JUnit 5.
Exception that indicates a test failed in JUnit 5.
The purpose of this exception is to encapsulate the same stack depth information provided by
TestFailedException, which is used when running with ScalaTest, but be reported as a failure not an error when running with JUnit. The stack depth information indicates which line of test code failed, so that when running with ScalaTest information can be presented to the user that makes it quick to find the failing line of test code. (In other words, when running with ScalaTest the user need not scan through the stack trace to find the correct filename and line number of the failing test.)JUnit distinguishes between failures and errors. If a test fails because of a failed assertion, that is considered a failure in JUnit. If a test fails for any other reason, either the test code or the application being tested threw an unexpected exception, that is considered an error in JUnit. This class differs from
TestFailedExceptionin that it extendsorg.opentest4j.AssertionFailedError. Instances of this class are thrown by the assertions provided byAssertionsForJUnit.The way JUnit 3 (JUnit 3.8 and earlier releases) decided whether an exception represented a failure or error is that only thrown
junit.framework.AssertionFailedErrors were considered failures. Any other exception type was considered an error. The exception type thrown by the JUnit 3 assertion methods declared injunit.framework.Assert(such asassertEquals,assertTrue, andfail) was, therefore,AssertionFailedError. In JUnit 4,junit.framework.AssertionFailedErrorwas made to extendjava.lang.AssertionError, and the distinction between failures and errors was essentially dropped. In JUnit 5,org.opentest4j.AssertionFailedErroris used instead as common base class for test-related AssertionErrors.- Exceptions thrown
NullArgumentExceptionif eithermessageorcauseisnull, orSome(null).
- class ScalaTestClassDescriptor extends AbstractTestDescriptor
TestDescriptorfor ScalaTest suite. - class ScalaTestDescriptor extends AbstractTestDescriptor
TestDescriptorfor a test in ScalaTest suite. - class ScalaTestEngine extends TestEngine
ScalaTest implementation for JUnit 5 Test Engine.
- trait VersionSpecificAssertionsForJUnit extends Assertions
Value Members
- object AssertionsForJUnit extends AssertionsForJUnit
Companion object that facilitates the importing of
AssertionsForJUnitmembers as an alternative to mixing it in.Companion object that facilitates the importing of
AssertionsForJUnitmembers as an alternative to mixing it in. One use case is to importAssertionsForJUnitmembers so you can use them in the Scala interpreter:sbt:junit-5.9> console [info] Starting scala interpreter... Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 1.8.0_352). Type in expressions for evaluation. Or try :help. scala> import org.scalatestplus.junit5.AssertionsForJUnit._ import org.scalatestplus.junit5.AssertionsForJUnit._ scala> assert(1 === 2) org.scalatestplus.junit5.JUnitTestFailedError: 1 did not equal 2 at org.scalatestplus.junit5.AssertionsForJUnit.newAssertionFailedException(AssertionsForJUnit.scala:64) at org.scalatestplus.junit5.AssertionsForJUnit.newAssertionFailedException$(AssertionsForJUnit.scala:63) at org.scalatestplus.junit5.AssertionsForJUnit$.newAssertionFailedException(AssertionsForJUnit.scala:111) at org.scalatestplus.junit5.AssertionsForJUnit$AssertionsHelper.macroAssert(AssertionsForJUnit.scala:148) ... 35 elided scala> val caught = intercept[StringIndexOutOfBoundsException] { "hi".charAt(-1) } val caught: StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException: String index out of range: -1 - object ScalaTestClassDescriptor
ScalaTestClassDescriptorcompanion object.