简体   繁体   English

测量Eclipse中测试用例中的Scala代码覆盖率

[英]Measure Scala Code coverage in testcases in Eclipse

I am in a situation, where I have a number of ScalaTest written tests (JUnit compatible), and I want to measure how good codecoverage I get, when running the test. 我处于这种情况,我有许多ScalaTest编写的测试(兼容JUnit),我想测量运行测试时我得到的代码覆盖率。

I don't want to use SBT directly, but have an Eclipse Scala project, in which I have a number of test cases that I want to run. 我不想直接使用SBT,但有一个Eclipse Scala项目,其中我有许多我想运行的测试用例。

What would be the best way for me to go? 对我来说最好的方法是什么?

I use EclEmma for code coverage in Eclipse. 我在Eclipse中使用EclEmma进行代码覆盖。 Install it using the update site. 使用更新站点安装它。

Note that it's won't show up in the Scala perspective, only the Java perspective, but that's ok because you can still run your Scala-based unit tests that way. 请注意,它不会出现在Scala透视图中,只显示Java透视图,但这没关系,因为您仍然可以通过这种方式运行基于Scala的单元测试。

When you install it, it adds a new "run" button to your toolbar. 安装时,它会在工具栏中添加一个新的“运行”按钮。 When you use this is runs the unit tests you choose, generates a coverage report, and highlights your code to show what has and has not been covered. 当您使用它时,运行您选择的单元测试,生成覆盖率报告,并突出显示您的代码以显示已覆盖和未覆盖的内容。

I just tested it with a Scala project with Scala unit tests, and it seems to work fine. 我刚刚使用Scala单元测试Scala项目测试它,它似乎工作正常。

I have this working in scala for "plain scalatest classes" 我在scala中使用“普通的scalatest类”

all it requires is to add an annotation to your scalatest class to make it run as a Junit (see annotation below). 它需要的是在你的scalatest类中添加一个注释,使它作为Junit运行(参见下面的注释)。 This uses scalatests own junitrunner. 这使用了scalatests自己的junitrunner。

@RunWith(classOf[JUnitRunner]) class MyTest extends FeatureSpec with Matchers with GivenWhenThen with StrictLogging { @RunWith(classOf [JUnitRunner])类MyTest使用带有StrictLogging的GivenWhenThen的Matchers扩展FeatureSpec {

once you've done that, you will see that you can now run this class in eclipse as a "scala junit test". 一旦你完成了,你会发现你现在可以在eclipse中运行这个类作为“scala junit test”。 You will also be able to "coverage as -> junit test" as well. 您还可以“覆盖为 - > junit test”。

If you have the eclemma plugin installed, then you will see the coverage panel (you may have to manually add this to your scala perspective) with the coverage provided by your test and you will also get the red/green/yellow line by line coverage in your classes. 如果您安装了eclemma插件,那么您将看到覆盖面板(您可能需要手动将其添加到您的scala透视图中),并且测试提供的覆盖范围也是如此,您还将获得红色/绿色/黄色的逐行覆盖在你的课堂上。

life is good! 生活很好!

Check SCCT https://github.com/mtkopone/scct http://mtkopone.github.com/scct/ 检查SCCT https://github.com/mtkopone/scct http://mtkopone.github.com/scct/

Unfortunately, doesn't have Eclipse plugins (yet) 不幸的是,没有Eclipse插件(还)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM