Android: Inject fake camera preview for testing purpose
up vote
5
down vote
favorite
I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback
method of the android.hardware.Camera
class. I am looking for a way to inject a fake preview picture to test the app's behavior.
I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback
object, but unfortunately, the instance variable mPreviewCallback
is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback
object.
Another way I thought about was to send a Message
to the Camera's EventHandler
, but again the field mEventHandler
is private, so the test code has no way to get a reference to the Handler.
android android-camera android-testing
|
show 1 more comment
up vote
5
down vote
favorite
I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback
method of the android.hardware.Camera
class. I am looking for a way to inject a fake preview picture to test the app's behavior.
I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback
object, but unfortunately, the instance variable mPreviewCallback
is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback
object.
Another way I thought about was to send a Message
to the Camera's EventHandler
, but again the field mEventHandler
is private, so the test code has no way to get a reference to the Handler.
android android-camera android-testing
1
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46
|
show 1 more comment
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback
method of the android.hardware.Camera
class. I am looking for a way to inject a fake preview picture to test the app's behavior.
I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback
object, but unfortunately, the instance variable mPreviewCallback
is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback
object.
Another way I thought about was to send a Message
to the Camera's EventHandler
, but again the field mEventHandler
is private, so the test code has no way to get a reference to the Handler.
android android-camera android-testing
I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback
method of the android.hardware.Camera
class. I am looking for a way to inject a fake preview picture to test the app's behavior.
I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback
object, but unfortunately, the instance variable mPreviewCallback
is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback
object.
Another way I thought about was to send a Message
to the Camera's EventHandler
, but again the field mEventHandler
is private, so the test code has no way to get a reference to the Handler.
android android-camera android-testing
android android-camera android-testing
asked Dec 16 '13 at 18:37
lacton
1,63611622
1,63611622
1
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46
|
show 1 more comment
1
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46
1
1
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
add a comment |
up vote
0
down vote
Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
add a comment |
up vote
0
down vote
up vote
0
down vote
Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.
Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.
edited May 23 '17 at 10:30
Community♦
11
11
answered Dec 19 '13 at 10:29
Alex Cohn
40.2k551182
40.2k551182
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
add a comment |
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20618296%2fandroid-inject-fake-camera-preview-for-testing-purpose%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40
Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03
@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02
@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03
@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46