测试单元和辅助/演示程序

huangapple go评论58阅读模式
英文:

Test unit and helper/demonstrators

问题

我已经在Java中开发单元测试几年了,但我在面临一个新的技术需求时遇到了困难。我的问题更与测试组织和分类相关。

一方面,我有常规的单元测试用于业务逻辑。到目前为止还不错。
另一方面,我的一些开发人员正在使用测试单元来演示某些功能的使用。实际上,它更像是组件测试。它通常说明了库应该如何一起工作,或者开发人员应该如何开始使用一段代码。
它并不真正提高代码覆盖率,但它是代码模板知识的良好来源。这些测试不需要在每次构建时都运行。

我想知道你如何在项目中对这些测试进行分类?
首先是为了使开发人员能够轻松找到它们。
其次是为了避免每次都运行它们。

你会使用类命名吗?或者创建另一个名为"helpers"的测试文件夹?

英文:

I have been developing unit test in Javafor some years know but I am struggling with a new technical need. My question is more related to test organisation and classification.

I have regular unit test on one side for business logic. So far so good.
On the other side, some of my developers are using test unit to demonstrate some use of features. It looks like more as component test actually. It generally illustrates how libs should work together or how a developer should start using a piece of code.
It does not really improve code coverage but it is a good source of knowledge for code templates. There is no need for those tests to be launched at every build.

I wonder how you classify such tests in a project ?
First to find them easily for developers.
Secondly to avoid playing them all the time.

Woul'd you use class naming ? Create another test folder named helpers ?

答案1

得分: 1

If you are using JUnit 5, you can utilize Tagging and Filtering 如下:

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("fast")
@Tag("model")
class TaggingDemo {

    @Test
    @Tag("taxes")
    void testingTaxCalculation() {
    }

}

然后,如果你运行你的测试,例如使用gradle,你可以进行过滤,如下:

test {
    useJUnitPlatform {
        excludeTags 'taxes'
    }
}

参见此处

英文:

If you are using JUnit 5 you can utilize Tagging and Filtering e.g.

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("fast")
@Tag("model")
class TaggingDemo {

    @Test
    @Tag("taxes")
    void testingTaxCalculation() {
    }

}

and then if you run your tests e.g. with gradle you can filter it e.g.

test {
	useJUnitPlatform{
		excludeTags 'taxes'
	}
}

See here

huangapple
  • 本文由 发表于 2020年7月28日 20:39:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63134348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定