赞
踩
junit5 for gradle 环境配置
# build.gradle
- plugins {
- id 'java'
- }
-
- group 'org.example'
- version '1.0-SNAPSHOT'
-
- repositories {
- mavenCentral()
- }
-
- dependencies {
- testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
- testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
- testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.7.2'
- }
-
- test {
- useJUnitPlatform()
- }
编写一个测试类 src/test/sampleTest.java
- package com.rainbow;
-
- import org.junit.jupiter.api.*;
- import java.util.List;
-
- import static org.junit.jupiter.api.Assertions.assertEquals;
-
-
- public class SampleTest {
-
- @Test
- @DisplayName("list Test")
- void testList(){
- List<Integer> numbers= List.of(2,3,5,7);
- Assertions.assertEquals(2,numbers.get(0));
-
- }
- }
选中运行测试 ctrl+shift+F10
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。