Skip to content

Allow tests to be marked ignored or pending #193

@frgomes

Description

@frgomes

This issue is about providing simple functionalities for ignored and pending test cases.

I would like to contribute to uTest but I'm not sure if my suggestion would qualify to the skimmed down nature of uTest. I'm copying/pasting the overall idea here before submitting a PR, but only if I get approval from the project administrator. Otherwise, I will create a separate project. So, please let me know if my suggestion qualifies.

This is the overall idea:

  1. You mark test cases the same way as you would do in ScalaTest:
"This is an ignored test case" - ignored {
   // this is the test code
   assert(false)
}

"This test case is ignored when running by Jenkins" - ignoredif(jenkins) {
   // this test has requirements which Jenkins is not going to fulfill, for whatever reason
   assert(false)
}
  1. This is the barebones of how to provide the feature:
trait uTestActions {
  def ignored(action:  Unit): Unit = ignored
  def ignoredif(condition: Boolean)(action:  Unit): Unit = if(condition) ignored else action
  def pending(action:  Unit): Unit = {
    try {
      action
      pending("PENDING", new TestPendingException)
    } catch {
      case t: Throwable => pending("FAILED", new TestFailedException(t))
    }
  }

  private def ignored: Unit = {
    val t = new TestIgnoredException
    val it = t.getStackTrace.iterator
    val e = (1 to 5).map(_ => it.next).last
    report("IGNORED", e)
  }

  private def pending(state: String, t: Throwable): Unit = {
    val pos = t.getStackTrace.zipWithIndex.find(p => p._1.getMethodName == "pending").get._2
    val it = t.getStackTrace.iterator
    val e = (1 to pos+4).map(_ => it.next).last
    report(state, e)
  }

  private def report(state: String, e: StackTraceElement): Unit = {
    val _class  = e.getClassName
    val _method = e.getMethodName
    val _file   = e.getFileName
    val _line   = e.getLineNumber
    System.err.println(s"@@@@@@@@ ${state}:: ${_class}.${_method} at ${_file}:${_line}")
  }
}
class TestPendingException extends Exception
class TestIgnoredException extends Exception
class TestFailedException(cause: Throwable) extends Exception(cause)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions