Manually exclude some test classes in sbt
Asked Answered
B

3

7

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)

Bullet answered 20/3, 2015 at 9:24 Comment(0)
B
6

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"
    
Brood answered 20/1, 2021 at 22:37 Comment(0)
O
0

Including or excluding tests is dependent on the test framework you are using. The command you will be employing in SBT is not completely parsed by SBT, but partially parsed by SBT, partially parsed by the test framework you are using.

So, if you are suing scalameta/munit, you may enter a command like this:

sbt> myproject/Test/testOnly MyProjectTest -- --exclude-tags=tag1,tag2,tag3

If you are using another test framework, the specific syntax after -- will be probably different.

When you are writing your test cases, you have to add tags somewhere, obviously. More details can be found below:

Ordure answered 8/9, 2022 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.