问个JUNIT语法的问题
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os.cts;
import android.content.Context;
import android.os.Vibrator;
import android.test.AndroidTestCase;
import android.util.Log;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
@TestTargetClass(Vibrator.class)
public class VibratorTest extends AndroidTestCase {
private Vibrator mVibrator;
@Override
protected void setUp() throws Exception {
super.setUp();
mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
}
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test cancel()",
method = "cancel",
args = {}
)
public void testVibratorCancel() {
try {
mVibrator.vibrate(1000);
} catch (Exception e) {
fail("testVibratorCancel failed!");
}
sleep();
try {
mVibrator.cancel();
} catch (Exception e) {
fail("testVibratorCancel failed!");
}
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long[].class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long.class}
)
})
public void testVibratePattern() {
long[] pattern = {100, 200, 400, 800, 1600};
try {
mVibrator.vibrate(pattern, 3);
} catch (Exception e) {
fail("vibrate failed!");
}
try {
mVibrator.vibrate(pattern, 10);
fail("Should throw ArrayIndexOutOfBoundsException");
} catch (ArrayIndexOutOfBoundsException e) {
}
sleep();
}
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrator with multi thread.",
method = "vibrate",
args = {long.class}
)
public void testVibrateMultiThread() {
Log.d("*******VibratorTest", "MultiTreadTest");
new Thread(new Runnable() {
public void run() {
Log.d("*******VibratorTest", "Thread 1");
try {
mVibrator.vibrate(100);
} catch (Exception e) {
fail("MultiThread fail1");
}
}
}).start();
new Thread(new Runnable() {
public void run() {
Log.d("*******VibratorTest", "Thread 2");
try {
// This test only get two threads to run vibrator at the same time
// for a functional test,
// but it can not verify if the second thread get the precedence.
mVibrator.vibrate(1000);
} catch (Exception e) {
fail("MultiThread fail2");
}
}
}).start();
sleep();
}
private void sleep() {
try {
Thread.sleep(10000);
} catch (Exception e) {
}
}
}
问个低级的问题:下面这段是什么意思呀? @TestTargets是什么意思呀?
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long[].class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long.class}
)
})
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os.cts;
import android.content.Context;
import android.os.Vibrator;
import android.test.AndroidTestCase;
import android.util.Log;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
@TestTargetClass(Vibrator.class)
public class VibratorTest extends AndroidTestCase {
private Vibrator mVibrator;
@Override
protected void setUp() throws Exception {
super.setUp();
mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
}
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test cancel()",
method = "cancel",
args = {}
)
public void testVibratorCancel() {
try {
mVibrator.vibrate(1000);
} catch (Exception e) {
fail("testVibratorCancel failed!");
}
sleep();
try {
mVibrator.cancel();
} catch (Exception e) {
fail("testVibratorCancel failed!");
}
}
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long[].class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long.class}
)
})
public void testVibratePattern() {
long[] pattern = {100, 200, 400, 800, 1600};
try {
mVibrator.vibrate(pattern, 3);
} catch (Exception e) {
fail("vibrate failed!");
}
try {
mVibrator.vibrate(pattern, 10);
fail("Should throw ArrayIndexOutOfBoundsException");
} catch (ArrayIndexOutOfBoundsException e) {
}
sleep();
}
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrator with multi thread.",
method = "vibrate",
args = {long.class}
)
public void testVibrateMultiThread() {
Log.d("*******VibratorTest", "MultiTreadTest");
new Thread(new Runnable() {
public void run() {
Log.d("*******VibratorTest", "Thread 1");
try {
mVibrator.vibrate(100);
} catch (Exception e) {
fail("MultiThread fail1");
}
}
}).start();
new Thread(new Runnable() {
public void run() {
Log.d("*******VibratorTest", "Thread 2");
try {
// This test only get two threads to run vibrator at the same time
// for a functional test,
// but it can not verify if the second thread get the precedence.
mVibrator.vibrate(1000);
} catch (Exception e) {
fail("MultiThread fail2");
}
}
}).start();
sleep();
}
private void sleep() {
try {
Thread.sleep(10000);
} catch (Exception e) {
}
}
}
问个低级的问题:下面这段是什么意思呀? @TestTargets是什么意思呀?
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long[].class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long.class}
)
})
...全文
相关推荐
解决java junit单元测试@Test报错的问题
仔细阅读错误信息,根据提示定位问题所在。通过以上步骤,大多数情况下都可以解决Java JUnit单元测试中遇到的@Test报错问题。
详解IDEA JUnit5测试套件运行错误的问题
"解读IDEA JUnit5测试套件运行错误的问题"IDEA JUnit5测试套件运行错误的问题是指在使用IDEA 2017.3版本中,建立JUnit5的测试用例时,出现“java.lang.Exception
Spring Junit单元测试加载配置文件失败问题
然而,在使用Spring Junit进行单元测试时,可能会遇到加载配置文件失败的问题。本文将详细介绍这个问题的解决方法。
junit5.jar
这个名为"junit5.jar"的文件正是JUnit 5的核心库,它包含了执行单元测试所需的所有核心组件,包括JUnit Platform、JUnit Jupiter和JUnit Vintage。
JUnit报initializationError
**编译错误**:有时,由于语法错误或其他编译问题,编译后的类文件可能包含错误,导致运行时异常。解决这些问题的方法包括:- 检查并修复静态初始化代码中的错误。


