EE308 Lab11
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ |
|---|---|
| The Goal of This Assignment | Software Testing |
| Leader's MU STU ID and Name | 19103379_831902122 |
| Teammate 1's MU STU ID and Name | 19104065_831902128 |
| Teammate 2's MU STU ID and Name | 19103913_831902127 |
| Teammate 3's MU STU ID and Name | 19103964_831902125 |
| Teammate 4's MU STU ID and Name | 19104090_831902111 |
We test some functions of our back-end part of the program.
1. Junit assert test
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bcslr.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.bcslr.entity.User;
import org.springframework.test.context.junit4.SpringRunner;
// import org.junit.rules.ExpectedException;
// import org.springframework.util.Assert;
// import static org.junit.Assert.*;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
class BcslrApplicationTests extends ServiceImpl<UserMapper, User> {
@Test
public void test() {
// add assert test code between Begin and End, no other change allowed
/***********************Begin**************************/
Assert.assertEquals("var1" , var2, var1); //
// for example
/************************End***************************/
}
}


The Junit assertEquals function can check whether two values are same, and give the corresponding output like the error information.
2. Junit time test
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bcslr.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.bcslr.entity.User;
import org.springframework.test.context.junit4.SpringRunner;
// import org.junit.rules.ExpectedException;
// import org.springframework.util.Assert;
// import static org.junit.Assert.*;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
class BcslrApplicationTests extends ServiceImpl<UserMapper, User> {
/*
test timeout function
*/
@Test()
public void testTimeout(){
log.info("yybzjbs");
while(true){
log.info("yybzjbs");
}
}
}

The Junit time test function are capable to prevent the function run for overlong time, it can prevent them to run when the function reaches the timeout function limitation and output the wrong information.
3. Junit parameterized test
package com.example.bcslr;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.example.bcslr.Calculate;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
/**
* JUnit4 parameterized test
*/
@RunWith(Parameterized.class)
public class ParameterTest {
private final int input11;
private final int input22;
private final int expected;
public ParameterTest(int input11, int input22, int expected) {
this.input11 = input11;
this.input22 = input22;
this.expected = expected;
}
@Parameterized.Parameters()
public static Collection<Object> prepareData() {
return Arrays.asList(new Object[][]{
{3, 1, 2}, {5, 2, 3}//, {3,4,5}, {6,7,8}
});
}
@Test
public void testSub() {
Calculator cal = new Calculator();
assertEquals(cal.sub(input11, input22), expected);
}
// Calculator.java Junit Parameterized Test
/**
* Mathematical Calculation subtract
*/
public class Calculator {
public int sub(int a, int b) {
return a - b;
}
}
}

Junit parameterized test function makes it possible to run tests with multiple kinds of parameters, in we can test multiple parameters.
4. Junit Exception Test
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bcslr.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.bcslr.entity.User;
import org.springframework.test.context.junit4.SpringRunner;
// import org.junit.rules.ExpectedException;
// import org.springframework.util.Assert;
// import static org.junit.Assert.*;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
class BcslrApplicationTests extends ServiceImpl<UserMapper, User> {
@Test
void testnegid() {
User user = new User();
user.setName("王宁");
user.setAge(-1);//怎么改id??
}
}

Junit Exception Test will stick with the functions in the original places and throw exceptions as usual.
5. Junit Suite Test
package com.example.bcslr;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({TestDemo2.class,TestDemo.class})
public class TestSuite {
@org.junit.Test(timeout = 1000)
public void test2() {
// log.info("yybzjbs");
//log.info("yybzjbs");
System.out.println(1);
}
}

The two functions in the TestDemo2.java file are able to run fluently by using the junit.

The two functions in the TestDemo1.java file are able to run fluently by using the junit.

Junit Suite Test is capable to test the subset functions and files from the java files that include by Suite functions. In this way, it test all the functions and cases from TestDemo.java file and TestDemo2.java file. And, we can see the four cases all pass fluently like we test them individually, and we can see the running performance individually.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
EE308-Lab11-Software Testing
unittest for Python
EE308-Lab8-AlphaSprint Collection
EE308 Lab8 Alpha Sprint Collection1. Format Description2. 宁可累死自己,也要卷死同学 -Sprint Collection 1. Format Description The Link Your Class https://bbs.csdn.net/forums/MUEE308FZ The Link of Requirement of This Assignment https://bbs.csdn.net/topics/603251
【信息科学与工程学】【物理/化学科学和工程技术】知识体系073——电学基础04
。
弱电网下光伏并网逆变器序阻抗建模仿真复现扫频法【序阻抗判断稳定性】
内容概要:本文聚焦于弱电网条件下光伏并网逆变器的序阻抗建模与稳定性分析,系统阐述了基于扫频法的阻抗特性仿真与复现方法。通过构建正负序阻抗模型,深入剖析逆变器在弱电网环境中的动态响应特性,结合锁相环、电流环等关键控制环节对系统阻抗的影响机制,采用序阻抗稳定性判据评估多机并网或复杂电网条件下的系统稳定裕度。研究在Simulink平台中实现激励信号注入、频率响应采集与阻抗曲线绘制,为高比例新能源接入背景下并网系统的稳定性分析提供了可靠的仿真手段与理论支撑,尤其适用于SCI级别论文成果的复现与拓展验证。; 适合人群:电力电子、新能源并网技术及相关领域的硕士/博士研究生、科研人员,以及从事光伏逆变器、微电网稳定控制开发的工程技术人员。; 使用场景及目标:①掌握扫频法在电力电子装置阻抗建模中的具体实施流程;②理解并应用基于序阻抗的稳定性判据进行系统稳定边界分析;③用于高水平学术论文(如SCI期刊)中阻抗建模与稳定性分析部分的仿真复现与方法验证; 阅读建议:建议读者结合文中所述方法与提供的参考文献,自主搭建Simulink仿真模型,逐步完成扰动信号设计、数据采集、傅里叶分析及阻抗拟合全过程,深入探究控制参数变化对系统阻抗特性和稳定性的具体影响,强化理论与实践的融合能力。


