commit
cd85a2b9a3
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
public class CalOpion {
|
||||
public static int add(int a,int b){
|
||||
return a+b;}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
public class Calculator {
|
||||
static int result; //静态变量,用于存储运行结果
|
||||
public void add(int n) {
|
||||
result=result+n;
|
||||
}
|
||||
public void substract(int n) {
|
||||
result=result-1; //Bug: 正确的应该是 result =result-n
|
||||
}
|
||||
public void a(int n){
|
||||
}// 此方法尚未写好
|
||||
public void divide(int n){
|
||||
result=result/n;
|
||||
}
|
||||
public void square(int n){
|
||||
result=n*n;
|
||||
}
|
||||
public void squareRoot(int n) {
|
||||
for (; ;) ; //Bug : 死循环
|
||||
}
|
||||
public void clear() { // 将结果清零
|
||||
result = 0;
|
||||
}
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CalculatorTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.out.println("测试开始");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void add() {
|
||||
Calculator cal = new Calculator();
|
||||
cal.add(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substract() {
|
||||
/**数值匹配**/
|
||||
//测试变量是否大于指定值
|
||||
assertThat(501,greaterThan(50));
|
||||
//测试变量是否小于指定值
|
||||
assertThat(6,lessThan(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void divide() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void square() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void squareRoot() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResult() {
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package comd;
|
||||
|
||||
public class CalOpion {
|
||||
public static int add(int a,int b){
|
||||
return a+b;}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package comd;
|
||||
//带参数的测试用例
|
||||
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvFileSource;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CalTest {
|
||||
@Test
|
||||
public void test1(){
|
||||
assertNotNull("name");
|
||||
}
|
||||
@Test
|
||||
public void test2(){
|
||||
CalOpion cal=new CalOpion();
|
||||
int num= cal.add(3,5);
|
||||
assertEquals(8,num);
|
||||
}
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"test1","test2","test3"})
|
||||
public void test3(String str){
|
||||
assertNotNull(str);
|
||||
|
||||
}
|
||||
@DisplayName("单一参数循环")
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1,2,3,4,5,6,7,8,9})
|
||||
public void test4(int num){
|
||||
assertNotEquals(5,num);
|
||||
}
|
||||
@DisplayName("多个参数循环")
|
||||
@ParameterizedTest
|
||||
@CsvSource({"3,5,8","1,0,1","4,5,9"})
|
||||
public void test5(int a1,int a2,int a3){
|
||||
assertEquals(a3, CalOpion.add(a1,a2));
|
||||
|
||||
}
|
||||
public static Stream getString(){
|
||||
return Stream.of("java","c","oracle","apple");
|
||||
}
|
||||
|
||||
@DisplayName("一个方法的结果集 作为参数传入")
|
||||
@ParameterizedTest
|
||||
@MethodSource("getString")
|
||||
public void test6(String str){
|
||||
assertEquals("java",str);
|
||||
|
||||
}
|
||||
|
||||
public static List getList(){
|
||||
ArrayList list=new ArrayList();
|
||||
String [] s1={"admin","9999999","true"};
|
||||
|
||||
String [] s2={"admin","9999999","false"};
|
||||
String [] s3={"admin","9999999","true"};
|
||||
String [] s4={"admin","9999999","true"};
|
||||
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
list.add(s4);
|
||||
|
||||
return list;
|
||||
|
||||
|
||||
}
|
||||
@DisplayName("方法返回list结果集")
|
||||
@ParameterizedTest
|
||||
@MethodSource("getList")
|
||||
public void test7(Object username,String password){
|
||||
System.out.println(username+"sssss"+password);
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("从文件来取数据")
|
||||
@ParameterizedTest
|
||||
@CsvFileSource(files = "/testvalue.csv",numLinesToSkip = 1)
|
||||
public void test8(String username,String password){
|
||||
System.out.println(username+"----"+password);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
Loading…
Reference in new issue