0

I am doing the Principles of Reactive Programming course from Coursera. In one of the assignments I need to use a scalacheck class. I have the following test class open in Intellij:

package quickcheck

import org.scalatest.FunSuite

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._

import org.scalatest.exceptions.TestFailedException

object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap

@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
  def checkBogus(p: Prop) {
    var ok = false
    try {
      check(p)
    } catch {
      case e: TestFailedException =>
        ok = true
    }
    assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
  }

  test("Binomial heap satisfies properties.") {
    check(new QuickCheckHeap with BinomialHeap)
  }

  test("Bogus (1) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus1BinomialHeap)
  }

  test("Bogus (2) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus2BinomialHeap)
  }

  test("Bogus (3) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus3BinomialHeap)
  }

  test("Bogus (4) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus4BinomialHeap)
  }

  test("Bogus (5) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus5BinomialHeap)
  }
}

When I am trying to run it I get this output:

+ Heap.min1: OK, passed 100 tests.
+ Heap.minOfTwo: OK, passed 100 tests.
+ Heap.insertAndDelete: OK, passed 100 tests.

Heap.min1, Heap.minOfTwo, Heap.insertAndDelete are the methods that I want to check so that's good. However, the tests that they pass have no connection whatsoever with the test file that I am trying to run.

How can I run this test file correctly from Intellij? Can I run it instead from somewhere else(like sbt console)?

bsky
  • 19,326
  • 49
  • 155
  • 270

2 Answers2

0

Do you use this library ScalaTest ? From sbt you can run you code / test it, compile and update library (more faster than in Intellij) and do many other useful things

  • as i understood you showed code from example. I think it will be better if to show your code. (more clear to andertend the problem).. Location for test must be: src/test/scala/. Maybe you miss some configuration. to run test in sbt: sbt > test – Александр Третьяк Mar 15 '16 at 12:45
0

In IntelliJ, having that file open in the editor does not ensure that it is the test class that will be run when you execute your tests. Your project can contain multiple run/debug configurations which you can edit with Run > Edit Configurations. To execute only the tests defined in quickcheck.QuickCheckSuite, you want a ScalaTest configuration with Test Class: set to quickcheck.QuickCheckSuite. Then you can execute it with Run > Run….

Or, from sbt, you can run

test-only quickcheck.QuickCheckSuite

Matt G
  • 2,373
  • 1
  • 14
  • 12