JUnit 5 最棒的 5 个新特性

@NestedConfigurationProperty 注解用法 注解在Spring Boot中用于标记配置类中的嵌套属性。这个注解通常用于当一个配置类拥有另一个非标量(非简单值,如自定义类型)属性时,指明该属性也应该被视为配置属性进行处理。 阅读详情

特性1 – 嵌套单元测试

       JUnit 5 的新 @Nested 注解特性可用于创建更干净的单元测试类,使用任意嵌套的内部类作为单个测试类中附加的测试组成单元。这使您能够将测试集中在一起,同时能以不同方式初始化它们来模拟不同的运行时条件。

       对代码执行单元测试,可以测试您的代码可能遇到的所有情况,但是如果无法理解单元测试报告,这又有什么用呢?将相关测试方法嵌套在同一个测试类中,再结合新的 @DisplayName 注解,会让您的单元测试在视觉上大变样。您的单元测试报告从未像现在这么美观!

特性2 – JUnit 扩展

       JUnit 5 扩展模型遵循 JUnit 5 团队的“扩展优于特性”的核心原则,并定义了很多扩展点(已经为它们提供了默认实现,但是还应该为它们创建扩展以覆盖默认行为)。这些扩展是您实现扩展点并注册到 JUnit 5 框架的回调接口,在运行单元测试的时候,当到达该扩展点时,就会调用您的代码。

       您可能从不需要编写自定义扩展,但好处在于,需要的时候,您可以使用工具供应商使用的相同 API。为了支持 JUnit,工具供应商常常使用其内部 API,这限制了 JUnit 维护者在该框架的演化过程中能做的事情(这是相互矛盾的)。扩展模型通过为您和工具供应商提供一致的公共 API,将推动 JUnit 不断演化。

而且,所有公共 API 方法都使用 @API 和类似下面这样的值进行注释:

Experimental – 该特性是新的,JUnit 团队欢迎提供反馈。

Internal – 该特性供 JUnit 内部使用,我们应该避免使用它。

Maintained – 该特性至少在下一个次要版本发布之前很不错(会以向后兼容方式更改)。

扩展让JUnit 5 变得如此灵活,应该使用 JUnit Yoga 作为它的代号。

特性3 – 条件

        谈到扩展,JUnit 5 提供了两个扩展点 – ContainerExecutionCondition 和 TestExecutionCondition接口 – 它们组成了测试执行条件 API。当然,JUnit 4 允许我们通过 @Ignore 注解测试类或方法,JUnit 5 通过 @Disabled 注解来提供此行为。

但是如果您愿意,可以为两种测试执行条件 API 方法中的一个创建自己的自定义扩展,以检查当前正在运行的测试,并动态决定是否要运行一个测试类(通过 ContainerExecutionCondition)或方法(通过 TestExecutionCondition)。

等等,还有更多!JUnit 5 甚至允许您停用条件,比如说通过 @Disabled 禁用单元测试,所以您也可以运行这些单元测试来查看其是否仍然处于禁用状态。太棒了!

特性4 – Lambda 支持

       Lambda表达式的编写紧凑代码能力非常方便。

       现在该特性已通过使用一些新函数型接口(比如 Executable)而集成到 JUnit 5 中。Assertions.assertAll() 之类的方法接受 Executable... 作为一个可变参数,您可以将该参数替换为一个 lambda 表达式。

        断言(Assertions)和前置条件(Assumptions)中的其他方法使用诸如 Supplier<String> 之类的函数式接口,这使您能够分别使用 lambda 表达式提供消息,使用 BooleanSupplier 提供布尔值结果。

特性5 – 参数化测试

       编写单元测试可能很枯燥,尤其是当您需要使用不同的输入来运行同一个单元测试时。在这种情况下,您必须编写多个单元测试方法,或者在一个方法中编写多个块(这可能给您的单元测试留下不好的印象)。您是否曾经希望让您的单元测试更加动态?如果您可以将一个单元测试方法设置为运行多次,每次使用不同的输入值,那该多好?

       借助参数化测试,JUnit 5 允许您指定一个或多个来源,为您的单元测试方法提供其运行测试所需的参数值。来源生成参数值,JUnit 5 然后将参数值传递给您的单元测试方法(一次一个),直到传完来源中的所有参数值。以下是 JUnit 5 提供的一些开箱即用来源的示例:

       @ValueSource – 用于指定一个基本文字数组,这些文字将一次一个地传递给测试方法。

       @MethodSource – 用于在测试类中指定一个或多个静态的无参数方法,它们返回一个 Stream、Iterable、Iterator 或参数值  数组供您的测试方法使用。

       @CsvSource – 用于指定一组传递给测试方法的文字(基于测试方法中的参数数量而分解为元组)。

       @ArgumentSource – 用于创建您自己的自定义参数提供程序。

附加:参数化测试代码示例:

package com.test.atchk.blockchain.chaincode.contract;

import com.test.atchk.blockchain.chaincode.builder.CampaignBeBuilder;
import com.test.atchk.blockchain.chaincode.builder.FulfilledBeResultBuilder;
import com.test.atchk.blockchain.chaincode.builder.TestBuilder;
import com.test.atchk.blockchain.chaincode.enumeration.StateEventStatus;
import com.test.atchk.blockchain.chaincode.model.*;
import com.test.atchk.blockchain.chaincode.service.CampaignBeService;
import com.test.atchk.blockchain.chaincode.service.CsService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CampaignBeahaviourSpendWithTxnValueTestV2 {

    //the service of the test
    CampaignBeService testBeService;

    //the the arguments of the method
    String testID = "CAMPAIGN001";
    String testKey = "TEAM001";
    List<String> tests = Arrays.asList("MEM001");
    String testEnrolDate = OffsetDateTime.now().minusDays(7).toString();

    //Txn ID
    String currentTestID = "TXN001";
    String currentTestID1 = "TXN002";
    String currentTestID2 = "TXN003";

    //BeRestriction
    CaTestDTO.BeRestriction totalNumOfTimesRestriction;
    CaTestDTO.BeRestriction qualifyingMinimumTxnValue;
    CaTestDTO.BeRestriction qualifyingLatLngRestriction;
    CaTestDTO.BeRestriction qualifyingPaymentTypeRestriction;
    CaTestDTO.BeRestriction qualifyingDaysOfWeekRestriction;
    CaTestDTO.BeRestriction qualifyingTimeOfDayRestriction;
    CaTestDTO.BeRestriction qualifyingTimeFrameRestriction;
    CaTestDTO.BeRestriction prerequisiteBeRestriction;

    //builder the expected outcomes
    List<OutcomeDTO> expectedOutcomes = Arrays.asList(new OutcomeDTO()
            .setAmount(new BigDecimal(100))
            .setOrigin(new OutcomeDTO.Origin("OUTCOME001", "", "",  "")) // TODO: [assignee:Fiona] help fill in testID and TeamID, and txnIDs
                    .setMemberId("MEM001")
            .setType("point"));

    //builder the expected result
    FulfilledBeResult expectGetResults = FulfilledBeResultBuilder.fulfilledBeResultResult(true, Arrays.asList(currentTestID, currentTestID1, currentTestID2), expectedOutcomes);
    FulfilledBeResult expectNoResults = FulfilledBeResultBuilder.fulfilledBeResultResult(false, new ArrayList<>(), null);

    @BeforeAll
    public void setUp() {
        testBeService = CampaignBeService.getInstance();

        totalNumOfTimesRestriction = CampaignBeBuilder.buildTotalNumOfTimesEventRestriction("totalNumEvent_001", 3, true);
        qualifyingLatLngRestriction = CampaignBeBuilder.buildQualifyingLatLngTxnRestriction("LatLng_001", new BigDecimal(1), new BigDecimal(2), new BigDecimal(3));
        qualifyingPaymentTypeRestriction = CampaignBeBuilder.buildQualifyingPaymentTypeTxnRestriction("PAYMENT_001", "cash");
        qualifyingDaysOfWeekRestriction = CampaignBeBuilder.buildQualifyingDaysOfWeekTxnRestriction("Days_Of_WEEK_ID_001", Arrays.asList(
                DayOfWeek.MONDAY,
                DayOfWeek.TUESDAY,
                DayOfWeek.WEDNESDAY,
                DayOfWeek.THURSDAY,
                DayOfWeek.FRIDAY,
                DayOfWeek.SATURDAY,
                DayOfWeek.SUNDAY
        ));
        qualifyingTimeOfDayRestriction = CampaignBeBuilder.buildQualifyingTimeOfDayTxnRestriction("TIME_Of_DAY_001", Arrays.asList(
                new TimeOfDayDTO().setFrom("08:10").setTo("10:14"),
                new TimeOfDayDTO().setFrom("20:11").setTo("23:59")
        ));
        qualifyingTimeFrameRestriction = CampaignBeBuilder.buildQualifyingTimeframeTxnRestriction("TIME_FRAME_ID_001", 123456);
        prerequisiteBeRestriction = CampaignBeBuilder.buildPrerequisiteBeEventRestriction("prerequisiteBe_001", "A", false);
        qualifyingMinimumTxnValue = CampaignBeBuilder.buildQualifyingMinimumTxnValueTxnRestriction("Min_NumTxn_001", new BigDecimal(100));
    }

    Stream<Arguments> providerTheTestArgumentsOfPas() {

        CaTestDTO.BeEvent beEvent_4_1_1 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", false, totalNumOfTimesRestriction, qualifyingMinimumTxnValue);
        CaTestDTO.Be be_4_1_1 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_1, new BigDecimal(100));
 
        CaTestDTO.BeEvent beEvent_4_1_2 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", false, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(qualifyingLatLngRestriction);
        CaTestDTO.Be be_4_1_2 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_2, new BigDecimal(100));
  
        CaTestDTO.BeEvent beEvent_4_1_3 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", false, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(qualifyingPaymentTypeRestriction);
        CaTestDTO.Be be_4_1_3 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_3, new BigDecimal(100));
 
        CaTestDTO.BeEvent beEvent_4_1_4 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", false, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(qualifyingDaysOfWeekRestriction);
        CaTestDTO.Be be_4_1_4 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_4, new BigDecimal(100));
   
        CaTestDTO.BeEvent beEvent_4_1_5 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", true, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(qualifyingTimeOfDayRestriction);
        CaTestDTO.Be be_4_1_5 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_5, new BigDecimal(100));

        CaTestDTO.BeEvent beEvent_4_1_6 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", true, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(qualifyingTimeFrameRestriction);
        CaTestDTO.Be be_4_1_6 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_6, new BigDecimal(100));
   
        CaTestDTO.BeEvent beEvent_4_1_7 = CampaignBeBuilder.buildPurchaseSpendWithTestValue("CAMPAIGN001", false, totalNumOfTimesRestriction, qualifyingMinimumTxnValue).addRestriction(prerequisiteBeRestriction);
        CaTestDTO.Be be_4_1_7 = CampaignBeBuilder.buildBeWithSingleEventWithFixedPointOutcome("Behave001", beEvent_4_1_7, new BigDecimal(100));

        return Stream.of(

                Arguments.of(this.transactionTest_4_1_1_GetResult(),be_4_1_1,expectGetResults),

                Arguments.of(this.transactionTest_4_1_1_NoResult(),be_4_1_1,expectNoResults),

                Arguments.of(this.transactionTest_4_1_2_GetResult(),be_4_1_2,expectGetResults),

                Arguments.of(this.transactionTest_4_1_2_NoResult(),be_4_1_2,expectNoResults),

                Arguments.of(this.transactionTest_4_1_3_GetResult(),be_4_1_3,expectGetResults),

                Arguments.of(this.transactionTest_4_1_3_NoResult(),be_4_1_3,expectNoResults),

                Arguments.of(this.transactionTest_4_1_4_GetResult(),be_4_1_4,expectGetResults),

                Arguments.of(this.transactionTest_4_1_4_NoResult(),be_4_1_4,expectNoResults),

                Arguments.of(this.transactionTest_4_1_5_GetResult(),be_4_1_5,expectGetResults),

                Arguments.of(this.transactionTest_4_1_5_NoResult(),be_4_1_5,expectNoResults),

                Arguments.of(this.transactionTest_4_1_6_GetResult(),be_4_1_6,expectGetResults),

                Arguments.of(this.transactionTest_4_1_6_NoResult(),be_4_1_6,expectNoResults),

                Arguments.of(this.transactionTest_4_1_7_GetResult(),be_4_1_7,expectGetResults),

                Arguments.of(this.transactionTest_4_1_7_NoResult(),be_4_1_7,expectNoResults)
        );
    }

    @ParameterizedTest
    @MethodSource("providerTheTestArgumentsOfPas")
    public void spendWithTxnValueTest(CpsDTO cps, CaTestDTO.Be be, FulfilledBeResult expectResult) {
        //testBeService.evaluateCampaignBe()为真正需要测试的方法
FulfilledBeResult result = testBeService.evaluateCampaignBe(cps,
                be,
                tests,
                currentTestID1);
        Assertions.assertEquals(expectResult, result);
    }

    public CpsDTO transactionTest_4_1_1_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        );
        return  cps;
    }

    public CpsDTO transactionTest_4_1_1_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(3).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(9).toString())
                        .payment(100)
                        .build()
        );
       return cps;
    }

    public CpsDTO transactionTest_4_1_2_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .location("LatLng001", new BigDecimal(1), new BigDecimal(2))
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .location("LatLng001", new BigDecimal(1), new BigDecimal(2))
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .location("LatLng001", new BigDecimal(1), new BigDecimal(2))
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_2_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .location("LatLng_001", new BigDecimal(2), new BigDecimal(2))
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .location("LatLng_001", new BigDecimal(1), new BigDecimal(2))
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .location("LatLng_001", new BigDecimal(1), new BigDecimal(2))
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_3_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(new BigDecimal(100), "cash")
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(new BigDecimal(100), "cash")
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(new BigDecimal(100), "cash")
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_3_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(new BigDecimal(100), "cash")
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(new BigDecimal(100), "cash")
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(new BigDecimal(100), "alipay")
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_4_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_4_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(10).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_5_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, "2019-12-13T22:00:00+08:00")
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, "2019-12-12T22:00:00+08:00")
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, "2019-12-11T22:00:00+08:00")
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_5_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(10).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_6_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }

   
    public CpsDTO transactionTest_4_1_6_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(10).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }

    public CpsDTO transactionTest_4_1_7_GetResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        );
        cps.addEvent("A", new CpsDTO.StateEvent().setStatus(StateEventStatus.FULFILLED));

        return cps;
    }


    public CpsDTO transactionTest_4_1_7_NoResult() {

        CpsDTO cps = CsService.createNewPas(testID + ":" + testKey, testID, tests, testEnrolDate);

        cps.addTestDetails(
                new TestBuilder()
                        .basic(currentTestID, OffsetDateTime.now().minusDays(6).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID1, OffsetDateTime.now().minusDays(7).toString())
                        .payment(100)
                        .build()
        ).addTestDetails(
                new TestBuilder()
                        .basic(currentTestID2, OffsetDateTime.now().minusDays(8).toString())
                        .payment(100)
                        .build()
        );
        return cps;
    }
}

结束语

还有其他一些有用的特性,比如:

单元测试(Junit) 单元测试 阅读详情

相关推荐

JUnit5进行单元测试及JUnit5的新特性

一、单元测试 单元测试就是模块测试,针对具体某块进行正确性的检验。在java这种,单元测试的最小单位是方法。单元测试属于白盒测试。 单元测试的优点: 1、提高软件的质量——能提前发现小模块里的问题,保障开发质量和程序的鲁棒性(面对发生很大的故障,程序还不至于崩溃); 2、减少重构时造成的影响——重构代码或者需求变动时,可能稍微改动了一点儿就引发一系列的bug,或者是改个小bug引发大bug。如果能做到单元测试,就可以让程序来检查是否有问题。 使用单元测试要注意的几个点: 1、要完全自动化,不要人为用Syst

wysghmbb的博客 1137

《单元测试》Junit5入门教程——非常详细,入门即精通

junit5入门教程,junit5依赖,常用注解,套件测试

雨水的早晨的博客 8614

Junit5

:用于 JVM 上启动测试框架的基础服务,提供命令行,IDE和构建工具等方式执行测试的支持。不仅支持 Junit 自制的测试引擎,其他测试引擎也都可以接入。:JUnit Jupiter 提供了 JUnit5 的新的编程模型和扩展模型,是 JUnit5 新特性的核心。内部包含了一个测试引擎,用于在 Junit Platform 上运行。:由于 JUint 已经发展多年,为了照顾老的项目,JUnit Vintage 提供了兼容 JUnit4.x、Junit3.x 的测试引擎。

专注于技术分享的博主 1239

Software Testing - JUnit 5 最棒的 5 个新特性

分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 您一定听说过 JUnit 5。它似乎很不错。所以,您可能想要迁移到 JUnit 5,但是不确定它是否像宣传的那样好,对吧?在这篇文章中,我将介绍 JUnit 5 的 5 个最佳的新特性和功能。阅读完这个清单后,您肯定迫切希望进行迁移。 特性 #1 – 嵌套单元测试 您是否曾经需要将相关的 JUnit 测试组合到一起,编写一个 JUnit 测试套件来执行它们

了解➔熟悉➔掌握➔精通 571

Spring Boot测试之旅:JUnit 4与JUnit 5的趣味对决与详尽差异

JUnit 4是一个基于注解的测试框架,它允许开发者通过注解来标记测试方法,并使用@Before和@After注解在测试方法之前和之后执行一些准备和清理工作。JUnit 4具有广泛的社区支持和成熟的生态系统,可以与各种构建工具和集成测试框架集成。它适用于传统的Java项目,特别是那些还没有迁移到Java 8及更高版本的项目。在Spring Boot的测试旅程中,JUnit 4与JUnit 5各自扮演着重要的角色。JUnit 4作为传统的测试框架具有广泛的社区支持和成熟的生态系统;

专业深耕,技术前沿 1621

保姆级教程:在树莓派5B上用AI Kit跑YOLOv8,实测134fps的完整配置流程

本文提供了一份详细的树莓派5B搭配AI Kit部署YOLOv8的教程,从硬件组装到模型转换、优化和部署,最终实现134FPS的高帧率推理性能。通过Hailo-8L AI加速模块和HEF模型转换,这套方案为边缘AI计算提供了强大支持,适用于智能监控、无人机视觉导航等应用场景。

weixin_28725407的博客 456

JUnit4 / JUnit 5 全面详解【单元测试、Maven】

JUnit4 / JUnit 5 全面详解【单元测试、Maven】

青年有志 1万+

ADS使用Smith圆图进行阻抗匹配

在处理RF系统的实际应用问题时,总会遇到一些非常困难的工作,对各部分级联电路的不同阻抗进行匹配就是其中之一。一般情况下,需要进行匹配的电路包括天线与低噪声放大器(LNA)之间的匹配、功率放大器输出(RFOUT)与天线之间的匹配、LNA/VCO输出与混频器输入之间的匹配。匹配的目的是为了保证信号或能量有效地从“信号源”传送到“负载”。 阻抗匹配(impedance matching) 信号源内阻与所接传输线的特性阻抗大小相等且相位相同,或传输线的特性阻抗与所接负载阻抗的大小相等且相位相同,分别称为传输线的输

红茶绿茶和奶茶的博客 3万+

关于JUnit5 你必须知道的(二)JUnit 5的新特性

之前介绍了下JUnit 5的架构和如何在maven下运行JUnit 5测试。这篇博客主要介绍下JUnit 5的新特性

qq_35448165的博客 2010

无人机信号干扰系统设计实战:从链路预算到工程落地

在低空防护与安防集成领域,无人机的违规飞行已成为公共安全的重要威胁。要有效实施无人机反制,不能仅靠大功率压制设备,更需要理解目标无人机的通信链路特征与射频传播原理。通过自由空间损耗模型与链路预算分析,工程人员可精准估算干扰距离与所需有效辐射功率,从而在保证覆盖范围的同时兼顾电磁环境安全。干扰方式上,宽带压制与窄带瞄准各有适用场景,需结合频谱监测与光电识别形成闭环决策。从系统架构到外场测试,链路预算、频段选择、天线极化匹配及合规管理贯穿始终。本文基于实际项目经验,梳理干扰信号源设计、天线布设策略、告警联动逻辑

weixin_29169505的博客 340

自适应IIR格型滤波器的Matlab实现

概述 在现有的众多抑制窄带干扰的信号处理手段中,时域自适应陷波干扰抑制技术具有实现简单、抗干扰性能好等优点。IIR陷波器按照结构可以分为直接型和格型两种。相比自适应直接型IIR陷波器,自适应格型IIR陷波器不仅可以准确地控制滤波器的陷波频率,也可以准确地调整陷波器的带宽。 传递函数 二阶自适应IIR格型陷波器的传递函数H(z)为: 其中α与陷波带宽有关,β与陷波频率有关;对应的结构如下图所示: Matlab算法实现 ...

剑藏锋的博客 2807

JUnit5 与 JUnit4 区别及及新特性

Junit5架构与简述 Junit5 与以前的JUnit版本不同,JUnit 5由来自三个不同子项目的几个不同模块组成。 JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage JUnit Platform 作用于JVM上启动测试框架。还定义了开发在平台上运行的测试框架的TestEngine API。开发或测试人员可从命令行启动平台,...

枫的等待 3723

从婴儿学步到工业级应用:VLA的‘隐式标定‘原理通俗图解

本文深入解析VLA(Vision-Language-Action)模型的'隐式标定'原理,通过类比婴儿学习机制,揭示其如何替代传统手眼标定技术。文章对比了工业机器人传统标定与VLA数据驱动方法的差异,并可视化神经网络注意力机制,展示其在空间关系编码上的突破性进展。最后探讨了VLA在工业应用中的优势与混合架构解决方案。

pz890123456的博客 331

junit5教程_JUnit5教程

junit5教程 JUnit5教程 (JUnit5 Tutorial) In this Junit tutorial, we will introduce basics of JUnit5 and its new features using examples. In Java world, JUnit is one of the popular framework used to impleme...

从零开始的教程世界 4974

uniapp - 解决报错 TypeError: e[t] is not a function(Uniapp项目运行或打包编译时提示错误e[t] is not a function,全平台端均可搞定)

uniapp,报错,TypeError: e[t] is not a function,uniapp App端报错,Android端,苹果ios打包报错,运行报错,uniapp打包报错e[t] is not a function,无法运行提示错误,uniapp live-pusher直播推流,maps地图组件,uni-app live-pusher 报错TypeError: e[t] is not a function,uni-app maps报错TypeError: e[t] is not a funct

✅ 精选推荐文章 8226

KEPServerEX 6 之 lot Gateway MQTT Clinet 配置使用方式

IoT Gateway即Internet of Things Gateway物联网网关。 ---------------------------------------------------------------------------------- 方式:使用kepw的IOTGateway插件选择MQTTClient 解决:可以实现 KEPW 的Tag值 发送到 MQTT 服务器上 ----------------------------------------...

-雲飛兄-博客 6952

SpringBoot——单元测试之JUnit5

SpringBoot——单元测试之JUnit5

贝尔摩德苦艾酒 1万+

科技英语/专业英语——改错总结【2】

1.固定句式 make it + adj + 句子 例:These features make the electronic systems difficult to intercept this kind of signal. 正确形式:These features make it  difficult for the electronic systems  to intercept

MISAYAONE的博客 1735

JUnit5的新特性

前言: JUnit5比4增加了很多新特性,最近刚使用了一下JUnit5记录一下看到和使用了的新特性, 先看下JUnit5的的包结构 JUnit5的包结构: JUnit5和4开始支持的java版本也不一样,JUnit4需要Java 5或更高版本,JUnit 5需要Java 8或更高版本。 新特性: 1.断言 在Junit4中,org.junit.Assert具有所有断言方法来验证预期结果和结果。 例如: public static void assertEquals(long expected, long

我想问问天的专栏 350

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

JUnit5部分新特性

1.JUnit5简介 官方文档 1.1 组成模块 区别于junit4,Junit5由三个子模块组成: JUnit Platform:作为测试框架的基础平台,启动测试框架; JUnit Jupiter: JUnit5扩展的新的编程模型和扩展模型,功能模块核心,编写测试用例; JUnit Vintage:允许兼容JUnit3,4,在新的JUnit平台上运行旧的JUnit 3 和 4 的测试。 相比于j...

qq_43446343的博客 510

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Junit5简介和常用测试注解

文章目录Junit5简介和常用测试注解1、Junit5简介2、Junit5常用测试注解 Junit5简介和常用测试注解 SpringBoot从2.2.0版本开始就引入JUnit5作为单元测试的默认库。但是,从2.4以上的版本开始,移除了默认对Vintage的依赖(就是兼容JUnit4和JUnit3的模块)。如果需要兼容我们的JUnit4,那么我们就需要手动加入Junit4的依赖。 下面,我们就来介绍一下Junit5,并说一下他常用的测试注解。 1、Junit5简介 Junit5与之前版本有很大的不同,主要由

越努力越幸运的博客 3580

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

升级JUnit5及其特性介绍

本文记录了升级JUnit5、SpringBoot升级JUnit5的相关注意,并且介绍了JUnit5的部分新特性,具体内容包括: 1. JUnit5架构 2. JUnit5向下兼容JUnit4 3. JUnit5 & JUnit4常用注解对比 4. JUnit5 & JUnit4断言对比 5. JUnit5 & JUnit4假设对比 6. 设置JUnit5 测试类、测试方法的 执行顺序 7. JUnit5其他特性

罗小爬的技术宝书 2146

Junit4, Junit5, Jupiter之间的联系,Jupiter的使用指南,用IDEA和Jupiter生成可读性更好的测试报告

一次因为Jupiter而引发的思考 Jupiter和Junit5之间有什么联系? Jupiter提供了哪些新的测试方法? 如何用IDEA和Jupiter生成可读性更好的测试报告? Junit5 目前Java领域内最为流行的单元测试框架 ------ JUnit Junit的最新版本JUnit5于2017年发布。 Junit 5 = Junit Platform + Junit Jupiter + Junit Vintage Junit Platform: Junit Platform是在JVM上启动

weixin_45876795的博客 2万+

JUnit5的五大新特性

JUnit5的五大新特性 指定测试方法执行顺序 使用@TestMethodOrder(MethodOrderer.OrderAnnotation.class),然后使用@Order注解就可以指定一个类中方法执行的优先级,其中,数字越小,代表优先级越高。 @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class OrderedExecutionTest { @Test @Order(2) publ

hexin13666113593的博客 1179

JUnit 4 vs. JUnit 5

JUnit是一个开源的单元测试框架,专为Java编程语言设计。它提供了一种简单的机制,使得开发者可以在编写代码时快速创建和运行测试,从而验证程序的逻辑和功能是否按预期工作。JUnit最初是由Erich Gamma和Kent Beck于1997年创建的,最早目的在于支持测试驱动开发(TDD),并为程序测试提供一个标准化的框架。JUnit的发展历程与Java语言的演进密切相关。随着Java应用的普及,尤其是在企业级应用和大型软件开发项目中,测试的重要性逐渐被认识到。

不忘的博客 1556
上一篇: BlockChain之HyperLedger Fabric介绍
下一篇: 升级到JUnit5的7个理由
至学者
博客等级 码龄9年 180粉丝 773原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值