日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

est.java 2 错误 找不到符号_在命令行上用junit-4.12.jar和hamcrest-core-1.3.jar编译并运行测试?错误:是抽象的,无法实例化,找不到符号...

發布時間:2025/3/19 编程问答 25 豆豆

我正在嘗試做Java單元測試,這是我到目前為止所做的:

在文件test.java中:

import java.util.*;

public class Test{

public String getString(int n){

return String.valueOf(n);

}

public int max(int a, int b){

if(a>b) return a;

return b;

}

public int maxOf(int []a){

int max = Integer.MIN_VALUE;

for (int i=0; i

if (a[i]>max) max=a[i];

}

return max;

}

public String BMI(int weight, int height){

double BMI = weight/(height*height);

if(BMI < 18.5) return "Insufficient";

else if (BMI>=18.5 && BMI<=22.99) return "Normal";

else if (BMI>=23 && BMI<=24.99) return "Overweight";

return "Fat";

}

}

然后我在同一個目錄中編寫了另一個名為testtest.java的文件:

import static org.junit.Assert.*;

import org.junit.Test;

public class Testtest{

@Test

void testString(){

Test case1 = new Test();

String result = case1.getString(1);

// System.out.println(result);

assertEquals("1", result);

}

@Test

public void testMax(){

Test newTest = new Test();

int max = newTest.max(2, 4);

assertEquals(4, max);

}

@Test

public void testMaxOf(){

Test newTest = new Test();

int[] anArray = {

10,4,55,66,8,2,33,102

};

int max = newTest.maxOf(anArray);

assertEquals(102, max);

}

@Test

public void testBMI(){

Test newTest = new Test();

String result = newTest.BMI(60, 1.65);

assertEquals("Normal", result);

}

}

此目錄現在包含以下文件:

junit-4.12.jar

hamcrest-core-1.3.jar

Test.java

Testtest.java

然后我cd到命令行中的目錄中:

首先,我像往常一樣使用javac編譯test.java,然后使用下面的代碼編譯testest.java:

javac-cp junit-4.12.jar;。測試程序

我已經試過很多次了,我知道如果我使用IDE會更容易,但是出于很多原因,我真的希望只使用文本編輯器和命令行。

總結

以上是生活随笔為你收集整理的est.java 2 错误 找不到符号_在命令行上用junit-4.12.jar和hamcrest-core-1.3.jar编译并运行测试?错误:是抽象的,无法实例化,找不到符号...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。