Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running individual ScalaTest test methods in IntelliJ IDEA

Tags:

It is possible to run a single, selected JUnit test method in IntelliJ IDEA 12, however this does not seem to be possible with ScalaTest. You can run the whole test class or nothing, but there seems to be no finer grained control for ScalaTest (yet) in IntelliJ IDEA 12. (I haven't tried IDEA 13 yet.)

So, the question: Is there a way to execute only a single, selected ScalaTest test method in IntelliJ (like it is possible with JUnit test methods.)

Below is a code sample whose test methods I'd like to run individually in IntelliJ. Any idea how to do that?

I've tried JUnitRunner but that did not help.

class NodeDAOTest extends FlatSpec with SessionAware with BeforeAndAfter {    before{ IM3_SessionFactory.removeData   println("before is running")}   println("NodeDAOTest constructor.")   def numberOfNodes=initAndCloseDB(transaction{NodeDAO.numberOfNodes})     "Node" can "be added to DB and removed." in {     val n =new TextNode      assert(numberOfNodes===0)      initAndCloseDB { transaction{session save n}}      assert(numberOfNodes===1)      initAndCloseDB { transaction{deleteNode(n)}}      assert(numberOfNodes===0)   }    def getTag= initAndCloseDB {transaction{ session.createQuery("from Tag").list().get(0).asInstanceOf[Tag]}}   def getNode=initAndCloseDB {transaction{ session.createQuery("from Node").list().get(0).asInstanceOf[Node]} }    it can "be tagged and untagged" in {     val t=new Tag     val n=new TextNode      assert(numberOfNodes==0,"before adding one tag (and Node), there should be 0 Node in the DB")      initAndCloseDB{ transaction {addTag(t,n) }}      assert (getNode.getNumberOfTags===1)     assert (getTag.getNodes.size===1)      initAndCloseDB(transaction{removeTag(t,n)})      assert (numberOfNodes==1,"after removing the tag, there should be 1 Node in the DB")     assert (getNode.getNumberOfTags===0)     assert (getTag.getNodes.size===0)   }    "Tagged Node" can "be removed." in {     val f=new TagAndNodeFixture     assert(numberOfNodes==1)     initAndCloseDB{ transaction {addTag(f.t,f.n) }}     initAndCloseDB { transaction{deleteNode (f.n)} }     assert(numberOfNodes==0)     // the tag will be removed from the node   }    "Tag" can "be deleted and that will be removed from in-memory Nodes" in{    }    } 
like image 473
jhegedus Avatar asked Jan 25 '14 16:01

jhegedus


2 Answers

I use IntelliJ IDEA 13 and I am able to run single test when I use FunSuite - put cursor in a test and press Alt + Shift + F10 and the test is there. It is not possible with FlatSpec tests.

It has been added recently and I remember it wasn't working in version 12 even for FunSuite.

like image 90
František Hartman Avatar answered Sep 23 '22 07:09

František Hartman


You can generate a run configuration for a specific flatspec test by putting your cursor into the test, and from the Run menu select Run... (option+Shift+F10 on mac), and near the top will be an entry for the specific test.

You can manually generate the run configuration by selecting your test class as normal, then copying in the test name (The "foo" in "foo" should "bar" in...) into the Test Name field

like image 37
Daenyth Avatar answered Sep 23 '22 07:09

Daenyth