首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

JUnit5基础教程

JUnit5是Java的单元测试框架,用于测试Java程序代码。作为一名软件测试工程师,掌握JUnit是非常重要的。我们将从头开始,一步步学习JUnit5的用法。 一、准备工作 1. 在Maven项目中添加JUnit5依赖: <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> 2. 创建测试类:使用@Test注解标注测试方法,测试类名通常以Test结尾,如:MathTests。 public class MathTests { @Test void addition() { } } 二、第一条测试用例 我们在addition()方法中使用assertEquals()断言两个值相等: @Test void addition() { assertEquals(2, 1 + 1); } 三、运行测试 右键测试类名,选择“Run 'MathTests'”运行测试类。JUnit将检测@Test注解方法,执行它们,并报告测试结果。 四、JUnit注解 JUnit提供了许多测试相关注解: - @Test:标注测试方法 - @BeforeEach:每个测试方法前执行 - @AfterEach:每个测试方法后执行 - @RepeatedTest:重复测试多次 - @Timeout:测试方法超时时间 - @Disabled:忽略测试方法 - 等等 五、断言 我们可以在测试方法中使用各种断言来验证预期结果: - assertEquals(expected, actual) 两个值相等 - assertTrue(condition) 条件为真 - assertNull(object) 对象为空 - assertThrows(exceptionType, executable) 执行代码抛出异常 - 等等 六、测试套件与测试分组 JUnit支持把多个相关测试组织在一起: - @Suite用于注解测试套件类 - @RunWith(Suite.class)用于启动测试套件 - @Categories用于给测试类或方法添加分类 - 然后可以在套件中包含指定分类的测试 七、参数化测试 使用@ValueSource等注解,可以运行同一测试逻辑针对不同输入。 希望此详细教程能够帮助初级工程师彻底掌握JUnit5的使用。请在学习或使用中遇到任何问题,随时与我讨论。

02

使用infogan学习可解释的隐变量特征学习-及代码示例(代码和官方有差异)

In this week’s post I want to explore a simple addition to Generative Adversarial Networks which make them more useful for both researchers interested in their potential as an unsupervised learning tool 无监督, as well as the enthusiast or practitioner who wants more control over the kinds of data they can generate. If you are new to GANs, check out this earlier tutorial I wrote a couple weeks ago introducing them. The addition I want to go over in this post is called InfoGAN, and it was introduced in this paper published by OpenAI earlier this year. It allows GANs to learn disentangled latent representations, which can then be exploited in a number of useful ways. For those interested in the mathematics behind the technique, I high recommend reading the paper, as it is a theoretically interesting approach. In this post though, I would like to provide a more intuitive explanation of what InfoGANs do, and how they can be easily implemented in current GANs.

03
领券