Package

io.github.soc

testng

Permalink

package testng

Visibility
  1. Public
  2. All

Type Members

  1. class ScalaJSTestNGPlugin extends Plugin

    Permalink

    The Scala.js TestNG plugin is a way to overcome the lack of annotation information of any test class (usually accessed through reflection).

    The Scala.js TestNG plugin is a way to overcome the lack of annotation information of any test class (usually accessed through reflection). This is all the information required by the Scala.js testing framework to execute the tests.

    As an example we take the following test class:

    class Foo {
      @BeforeMethod def before(): Unit = {
        // Initialize the instance before the tests
      }
      @Test def bar(): Unit = {
        // assert some stuff
      }
      @Test(enabled = false) def baz(): Unit = {
        // assert some other stuff
      }
    }
    
    object Foo {
      @BeforeClass def beforeClass(): Unit = {
        // Initialize some global state for the tests.
      }
    }

    Will generate the following bootstrapper module:

    object Foo$scalajs$testng$bootstrapper extends io.github.soc.testng.TestNGTestBootstrapper {
    
      def metadata(): TestNGClassMetadata = {
        new TestNGClassMetadata(
          classAnnotations = List(),
          moduleAnnotations = List(),
          classMethods = List(
              new TestNGMethodMetadata(name = "before",
                  annotations = List(new BeforeMethod)),
              new TestNGMethodMetadata(name = "bar",
                  annotations = List(new Test)),
              new TestNGMethodMetadata(name = "baz",
                  annotations = List(new Test(enabled = false)))
          ),
          moduleMethods(
              new TestNGMethodMetadata(name = "beforeClass",
                  annotations = List(new BeforeClass)))
        )
      }
    
      def newInstance(): AnyRef = new Foo()
    
      def invoke(methodName: String): Unit = {
        if (methodName == "0") Foo.beforeClass()
        else throw new NoSuchMethodException(methodId)
      }
    
      def invoke(instance: AnyRef, methodName: String): Unit = {
        if (methodName == "before") instance.asInstanceOf[Foo].before()
        else if (methodName == "bar") instance.asInstanceOf[Foo].bar()
        else if (methodName == "baz") instance.asInstanceOf[Foo].baz()
        else throw new NoSuchMethodException(methodId)
      }
    }

    The test framework will identify Foo$scalajs$testng$bootstrapper as a test module because it extends TestNGTestBootstrapper. It will know which methods to run based on the info returned by Foo$scalajs$testng$bootstrapper.metadata, it will create new test instances using Foo$scalajs$testng$bootstrapper.newInstance() and it will invoke test methods using invoke on the bootstrapper.

Ungrouped