I recently tried to run my junit tests to ensure that I didn’t break anything after monkeying around with my code, and I ran into the following error:
|
1
|
Exception in thread "main" java.lang.RuntimeException: Stub!
|
Here’s my code that runs my tests:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public
class
RunTestSuite {
public
static
void
main(String[] a) {
TestRunner.run(suite());
}
public
static
Test suite() {
TestSuite suite =
new
TestSuite();
suite.addTestSuite(MyClassTests.
class
);
return
suite;
}
}
|
The stack trace pointed to line 8, so I didn’t know what to make of it since I just had this setup correctly, and TestSuite is a JUnit thing.
Googling mostly resulted in issues with using an Android Test Project (I’m not) and running the tests in your desktop’s JVM instead of the actual device’s (seehere).
Eventually, though, I foundthis postthat informed me that the JUnit library needs to be at the top of the test project’s build order.
Here are the steps to change the build order in Eclipse:
- Right-click your test project
- Click Bulid Path->Configure Build Path…
- Click the Order and Export tab
- Select the JUnit reference
- Click the Top button
本文介绍了一个常见的JUnit测试错误“RuntimeException: Stub!”及其解决方案。作者在运行单元测试时遇到此问题,并详细记录了如何通过调整Eclipse中项目的构建顺序来解决这个问题。
859

被折叠的 条评论
为什么被折叠?



