我一直有很多时间整合Robolectric和Ant或Maven,虽然Ant更有优势,因为它更贴近Android SDK。
一切都在日食中起作用。 Robolectric链接和单元测试运行,但是当我尝试从命令行运行并构建测试时,它似乎不起作用。
使用实际的Robolectric-sample应用程序,我尝试同时进行maven和ant构建。
使用ant构建成功,但测试都失败了。
Maven输出
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building RobolectricSample app 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0-beta-1:enforce (enforce-maven) @ robolectricsample ---
[INFO]
[INFO] --- android-maven-plugin:3.0.0-alpha-13:generate-sources (default-generate-sources) @ robolectricsample ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk\platform-tools\aapt.exe [package, -m, -J, C:\repos\Tests\robolectric-sample\target\generated-sources\r, -M, C:\repos\Tests\robolectric-sample\AndroidManifest.xml, -S, C:\repos\Tests\robolectric-sample\res, --auto-add-overlay, -I, C:\Program Files (x86)\Android\android-sdk\platforms\android-10\android.jar]
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ robolectricsample ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\repos\Tests\robolectric-sample\src\main\resources
[INFO] skip non existing resourceDirectory C:\repos\Tests\robolectric-sample\target\generated-sources\extracted-dependencies\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ robolectricsample ---
[INFO] Compiling 1 source file to C:\repos\Tests\robolectric-sample\target\classes
[INFO]
[INFO] --- android-maven-plugin:3.0.0-alpha-13:unpack (default-unpack) @ robolectricsample ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ robolectricsample ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\repos\Tests\robolectric-sample\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ robolectricsample ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.6:test (default-test) @ robolectricsample ---
[INFO] Surefire report directory: C:\repos\Tests\robolectric-sample\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.pivotallabs.api.HttpTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.53 sec <<< FAILURE!
Running com.pivotallabs.tracker.TrackerAuthenticationRequestTest
Warning: an error occurred while binding shadow class: ShadowActivity
Warning: an error occurred while binding shadow class: ShadowActivityGroup
Warning: an error occurred while binding shadow class: ShadowApplication
Warning: an error occurred while binding shadow class: ShadowItemizedOverlay
Warning: an error occurred while binding shadow class: ShadowListActivity
Warning: an error occurred while binding shadow class: ShadowMapActivity
Warning: an error occurred while binding shadow class: ShadowPreferenceActivity
Warning: an error occurred while binding shadow class: ShadowService
Warning: an error occurred while binding shadow class: ShadowTabActivity
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.361 sec <<< FAILURE!
Running com.pivotallabs.tracker.RecentActivityTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.01 sec
Running com.pivotallabs.ViewEnablingTextWatcherTest
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 0.008 sec <<< FAILURE!
Running com.pivotallabs.api.ApiGatewayTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.006 sec <<< FAILURE!
Running com.pivotallabs.NamesAdapterTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.NotifyDataSetChangedCallbacksTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.005 sec <<< FAILURE!
Running com.pivotallabs.GenericAdapterTest
Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.01 sec <<< FAILURE!
Running com.pivotallabs.tracker.AuthenticationGatewayTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.HomeActivityTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.NamesActivityTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.005 sec <<< FAILURE!
Running com.pivotallabs.tracker.RecentActivitiesTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.api.ApiResponseTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec
Running com.pivotallabs.injected.InjectedActivityTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.011 sec <<< FAILURE!
Running com.pivotallabs.MultiCallbacksTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec
Running com.pivotallabs.tracker.RecentActivityActivityTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.tracker.RecentActivityRequestTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec
Running com.pivotallabs.ViewVisibleWhileOutstandingCallbacksTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.005 sec <<< FAILURE!
Running com.pivotallabs.tracker.SignInDialogTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.004 sec <<< FAILURE!
Running com.pivotallabs.views.LoadingTextViewTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.003 sec <<< FAILURE!
Running com.pivotallabs.tracker.RecentActivityAdapterTest
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.007 sec <<< FAILURE!
Running com.pivotallabs.util.StringsTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Results :
Tests in error:
initializationError(com.pivotallabs.api.HttpTest)
shouldReturnUsernameAndPassword(com.pivotallabs.tracker.TrackerAuthenticationRequestTest)
shouldHaveUrl(com.pivotallabs.tracker.TrackerAuthenticationRequestTest)
shouldNotEnableTheViewIfTheAnyOfTheEditTextsContainWhitespace(com.pivotallabs.ViewEnablingTextWatcherTest)
shouldEnableTheViewWhenAllEditTextsHaveText(com.pivotallabs.ViewEnablingTextWatcherTest)
shouldDisableTheViewWhenOneOfTheEditTextsHaveEmptyText(com.pivotallabs.ViewEnablingTextWatcherTest)
initializationError(com.pivotallabs.api.ApiGatewayTest)
initializationError(com.pivotallabs.NamesAdapterTest)
onSuccessShouldNotifyDataSetChanged(com.pivotallabs.NotifyDataSetChangedCallbacksTest)
getCount_shouldReturnListSize(com.pivotallabs.GenericAdapterTest)
getItem_shouldReturnObjectAtIndex(com.pivotallabs.GenericAdapterTest)
getView_shouldCallThroughToGetView(com.pivotallabs.GenericAdapterTest)
getItemId_shouldReturnIndex(com.pivotallabs.GenericAdapterTest)
initializationError(com.pivotallabs.tracker.AuthenticationGatewayTest)
initializationError(com.pivotallabs.HomeActivityTest)
initializationError(com.pivotallabs.NamesActivityTest)
initializationError(com.pivotallabs.tracker.RecentActivitiesTest)
initializationError(com.pivotallabs.injected.InjectedActivityTest)
initializationError(com.pivotallabs.tracker.RecentActivityActivityTest)
shouldSetProgressBarVisibility(com.pivotallabs.ViewVisibleWhileOutstandingCallbacksTest)
initializationError(com.pivotallabs.tracker.SignInDialogTest)
initializationError(com.pivotallabs.views.LoadingTextViewTest)
shouldRecycleViews(com.pivotallabs.tracker.RecentActivityAdapterTest)
shouldCreateViews(com.pivotallabs.tracker.RecentActivityAdapterTest)
蚂蚁测试输出
test:
[junit] Warning: an error occurred while binding shadow class: ShadowActivity
[junit] Warning: an error occurred while binding shadow class: ShadowActivityGroup
[junit] Warning: an error occurred while binding shadow class: ShadowApplication
[junit] Warning: an error occurred while binding shadow class: ShadowListActivity
[junit] Warning: an error occurred while binding shadow class: ShadowMapActivity
[junit] Warning: an error occurred while binding shadow class: ShadowPreferenceActivity
[junit] Warning: an error occurred while binding shadow class: ShadowService
[junit] Warning: an error occurred while binding shadow class: ShadowTabActivity
[junit] Test com.pivotallabs.GenericAdapterTest FAILED
[junit] Test com.pivotallabs.HomeActivityTest FAILED
[junit] Test com.pivotallabs.NamesActivityTest FAILED
[junit] Test com.pivotallabs.NamesAdapterTest FAILED
[junit] Test com.pivotallabs.NotifyDataSetChangedCallbacksTest FAILED
[junit] Test com.pivotallabs.ViewEnablingTextWatcherTest FAILED
[junit] Test com.pivotallabs.ViewVisibleWhileOutstandingCallbacksTest FAILED
[junit] Test com.pivotallabs.api.ApiGatewayTest FAILED
[junit] Test com.pivotallabs.api.HttpTest FAILED
[junit] Test com.pivotallabs.injected.InjectedActivityTest FAILED
[junit] Test com.pivotallabs.tracker.AuthenticationGatewayTest FAILED
[junit] Test com.pivotallabs.tracker.RecentActivitiesTest FAILED
[junit] Test com.pivotallabs.tracker.RecentActivityActivityTest FAILED
[junit] Test com.pivotallabs.tracker.RecentActivityAdapterTest FAILED
[junit] Test com.pivotallabs.tracker.SignInDialogTest FAILED
[junit] Test com.pivotallabs.tracker.TrackerAuthenticationRequestTest FAILED
[junit] Test com.pivotallabs.views.LoadingTextViewTest FAILED
BUILD FAILED
C:\repos\Tests\robolectric-sample\build.xml:145: Unit test(s) failed. See reports!
编译和链接似乎对样本很好,但仍有很多测试失败。如果它们正常工作,我认为这些样本应该100%成功。
任何人都能揭开内在的神秘面纱吗?我可以在构建脚本中包含junit和robolectric测试,或者这是因为android构建系统在几个月前进行了这些更改,所以这是不正确支持的。