Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually exclude some test classes in sbt

I usually do below command in my CI:

clean update compile test publish

However, I'd like to exclude 1 (or a few) test class from the sbt command line.

How can I do this? (I don't want to change my code to use ignore, etc)

like image 334
anuni Avatar asked Mar 20 '15 09:03

anuni


People also ask

How to exclude dependencies in sbt?

We exclude dependencies in SBT by using either the exclude or excludeAll keywords. It's important to understand which one to use: excludeAll is more flexible but cannot be represented in a pom. xml. Therefore, we should use exclude if a pom.

Does sbt run tests in parallel?

By default, sbt executes tasks in parallel (subject to the ordering constraints already described) in an effort to utilize all available processors. Also by default, each test class is mapped to its own task to enable executing tests in parallel.

How do I clear my sbt cache?

You can use Pretty Clean to clean the all of dev tools caches including SBT. PrettyClean also cleans the SBT project's target folder.


2 Answers

Two possible options

  1. test-only See http://www.scalatest.org/user_guide/using_scalatest_with_sbt
  2. Tags http://www.scalatest.org/user_guide/tagging_your_tests
like image 105
Gonfva Avatar answered Sep 29 '22 06:09

Gonfva


Just to elaborate on the 2 correct options @Gonfva suggested above:

  1. To use testOnly you should run:

    sbt "testOnly org.fully.qualified.domainn.name.ASpec"
    

    When the argument is the FQDN of the class. You can use multiple classes separate them by space. This can be used with glob as well. For example:

    sbt "testOnly *ASpec"
    
  2. Using tags. First, define a tag:

    import org.scalatest.Tag
    object CustomTag extends Tag("tagName")
    

    Then, define a test with this tag:

    it should "test1" taggedAs CustomTag in { println("test1") }
    

    Now, in order to include tests using this tag, run:

    sbt "testOnly * -- -n tagName"
    

    Note: * is a wild card. It can be any glob as described in section 1.

    In order to exclude this tag, you need to run:

    sbt "testOnly * -- -l aaa"
    
like image 23
Tomer Shetah Avatar answered Sep 29 '22 06:09

Tomer Shetah