问题一:
预期结果:验证添加@ResourceLock后,并行使用公共资源时不会报错
实际结果:添加@ResourceLock后也报错了(查看视频22-Junit5进阶-Junit5并行数据同步前半段视频)
问题二:
自定义资源值时,设置的全局变量private static final String GOLBAL_USER = “com.ceshiren.entity.User.user”;中"com.ceshiren.entity.User.user"是包名+类名+任意值吗?其中的user是不是就可以随意命名(查看视频22-Junit5进阶-Junit5并行数据同步后半段视频)
问题一报错截图如下,烦请各位老师看一下原因:
问题一代码如下:
package com.ceshiren.syntem;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ;
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ_WRITE;
@Execution(CONCURRENT)
public class ParallelResourceLockTest {
Properties properties;
@BeforeEach
void before(){
properties = new Properties(System.getProperties());
}
@Test
@ResourceLock(value = Resources.SYSTEM_PROPERTIES,mode = READ)
void test1(){
System.out.println("test1属性值=》"+System.getProperty("custom.property"));
assertNull(System.getProperty("custom.property"));
}
@Test
@ResourceLock(value = Resources.SYSTEM_PROPERTIES,mode = READ_WRITE)
void test2(){
System.setProperty("custom.property","ceshiren");
System.out.println("test2属性值=》"+System.getProperty("custom.property"));
assertEquals("ceshiren",System.getProperty("custom.property"));
}
@Test
@ResourceLock(value = Resources.SYSTEM_PROPERTIES,mode = READ_WRITE)
void test3(){
System.setProperty("custom.property","hogwarts");
System.out.println("test3属性值=》"+System.getProperty("custom.property"));
assertEquals("hogwarts",System.getProperty("custom.property"));
}
}
问题二:截图