Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why statement coverage is not 100% in this class? #382

Open
omerlh opened this issue Oct 25, 2021 · 10 comments
Open

Why statement coverage is not 100% in this class? #382

omerlh opened this issue Oct 25, 2021 · 10 comments

Comments

@omerlh
Copy link

omerlh commented Oct 25, 2021

Hello!
I have a lot of small classes, where scoverage says the coverage is not complete - in this case:

image

And I can't figure out why... Is this a bug? Here is the example class (I've redacted the actual code):

Screen Shot 2021-10-25 at 6 31 15

Is this a bug? Or am I missing something?

I am using the latest version:

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.1")
@omerlh
Copy link
Author

omerlh commented Oct 25, 2021

Similar question just about logger:
Screen Shot 2021-10-25 at 9 02 54

Why the actual log message is red? Is this another bug?

@pjfanning
Copy link

Is it possible that your tests run without enabling debug logging? If you don't enable debug logging, then the message won't be evaluated because it is not needed.

@omerlh
Copy link
Author

omerlh commented Oct 27, 2021

Ahhh yes this might be it. Do you have any idea what is the issue with the first image?

@ckipp01
Copy link
Member

ckipp01 commented Nov 4, 2021

I have a lot of small classes, where scoverage says the coverage is not complete - in this case:

So on the page in the first image if you click "Statement List", does it show you the statements that aren't covered? I'm assuming there are 3 looking at the numbers?

@omerlh
Copy link
Author

omerlh commented Nov 7, 2021

This is the statement list:
image

@ckipp01
Copy link
Member

ckipp01 commented Nov 7, 2021

🤔 really? That's odd as the first image you showed says there are 35 statements

@omerlh
Copy link
Author

omerlh commented Nov 7, 2021

Yep I know! This is really word. Let me try reproduce it in a clean project I can share publicly...

@omerlh
Copy link
Author

omerlh commented Nov 7, 2021

Also, for some reason the table is incomplete - it does not have the tests or code columns...

@nigeleke
Copy link

nigeleke commented Jan 3, 2023

I have another example to add to the "Why statement coverage not 100%"

Code:

object Stuff:

  enum Foo:
    case Bar, Baz, Bam

  val wibble =
    (for thing <- Some(42) yield thing).getOrElse(0)

  val wobble =
    (for f <- Stuff.Foo.values yield f).toList

Test cases (scalatest):

class TestStuff extends AnyWordSpec with Matchers:

  "Stuff" should {

    "use for loop" in {
      val x = Stuff.wibble
      x should be(42)
    }

    "use object and enums" in {
      import Stuff.*
      val x = Stuff.wobble
      x should contain theSameElementsAs (Seq(Foo.Bar, Foo.Baz, Foo.Bam))
    }

  }

Test Coverage:

image

image

@nigeleke
Copy link

nigeleke commented Jan 3, 2023

Adding Set(...) example:
image
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants