Added End-2-End Test

This commit is contained in:
butomo1989 2017-06-01 15:51:22 +02:00
parent 59f6e4bd33
commit aff1b062e1
9 changed files with 126 additions and 56 deletions

View file

@ -93,8 +93,55 @@ get_android_versions
get_processors get_processors
function test() { function test() {
(export ANDROID_HOME=/root && export ANDROID_VERSION=5.0.1 && export API_LEVEL=21 \ # Prepare needed parameter to run tests
&& export PROCESSOR=x86 && export SYS_IMG=x86_64 && export IMG_TYPE=google_apis && nosetests -v) test_android_version=7.1.1
test_api_level=25
test_processor=x86
test_sys_img=x86_64
test_img_type=google_apis
test_image=test_img
test_container=test_con
# Run unit test
echo "----UNIT TEST----"
(export ANDROID_HOME=/root && export ANDROID_VERSION=$test_android_version && export API_LEVEL=$test_api_level \
&& export PROCESSOR=$test_processor && export SYS_IMG=$test_sys_img && export IMG_TYPE=$test_img_type \
&& nosetests src/tests/unit -v)
# Run integration test
# Integration test must be run only for linux OS / x86 image to reduce duration of test execution
if [ "$(uname -s)" == 'Linux' ]; then
echo "----BUILD TEST IMAGE----"
docker build -t $test_image --build-arg ANDROID_VERSION=$test_android_version \
--build-arg BUILD_TOOL=$LATEST_BUILD_TOOL --build-arg API_LEVEL=$test_api_level \
--build-arg PROCESSOR=$test_processor --build-arg SYS_IMG=$test_sys_img \
--build-arg IMG_TYPE=$test_img_type -f docker/Emulator_x86 .
echo "----RUN E2E TEST----"
docker run --privileged -d -p 4723:4723 -p 6080:6080 -e APPIUM=True --name $test_container $test_image
attempt=0
while [ ${attempt} -le 10 ]; do
attempt=$(($attempt + 1))
output=$(docker ps | grep healthy | grep test_con | wc -l)
if [[ "$output" == 1 ]]; then
echo "Emulator is ready."
break
else
echo "Waiting 10 seconds for emulator to be ready (attempt: $attempt)"
sleep 10
fi
if [[ $attempt == 10 ]]; then
echo "Failed!"
exit 1
fi
done
nosetests src/tests/e2e -v
echo "----REMOVE TEST CONTAINER----"
docker kill $test_container && docker rm $test_container
fi
} }
function build() { function build() {

View file

@ -1,3 +1,4 @@
Appium-Python-Client==0.24
coverage==4.2 coverage==4.2
mock==2.0.0 mock==2.0.0
nose==1.3.7 nose==1.3.7

View file

@ -1,54 +0,0 @@
"""Unit test to test app."""
import os
from unittest import TestCase
import mock
from src import app
class TestApp(TestCase):
"""Unit test class to test other methods in the app."""
def test_valid_env(self):
key = 'ENV_1'
os.environ[key] = 'test'
app.get_or_raise(key)
del os.environ[key]
def test_invalid_env(self):
with self.assertRaises(RuntimeError):
app.get_or_raise('ENV_2')
def test_valid_bool(self):
self.assertEqual(app.convert_str_to_bool('True'), True)
self.assertEqual(app.convert_str_to_bool('t'), True)
self.assertEqual(app.convert_str_to_bool('1'), True)
self.assertEqual(app.convert_str_to_bool('YES'), True)
def test_invalid_bool(self):
self.assertEqual(app.convert_str_to_bool(''), False)
self.assertEqual(app.convert_str_to_bool('test'), False)
def test_invalid_format(self):
self.assertEqual(app.convert_str_to_bool(True), None)
@mock.patch('src.app.prepare_avd')
@mock.patch('subprocess.Popen')
def test_run_with_appium(self, mocked_avd, mocked_subprocess):
with mock.patch('src.app.appium_run') as mocked_appium:
os.environ['APPIUM'] = str(True)
app.run()
self.assertTrue(mocked_avd.called)
self.assertTrue(mocked_subprocess.called)
self.assertTrue(mocked_appium.called)
@mock.patch('src.app.prepare_avd')
@mock.patch('subprocess.Popen')
def test_run_withhout_appium(self, mocked_avd, mocked_subprocess):
with mock.patch('src.app.appium_run') as mocked_appium:
os.environ['APPIUM'] = str(False)
app.run()
self.assertTrue(mocked_avd.called)
self.assertTrue(mocked_subprocess.called)
self.assertFalse(mocked_appium.called)

View file

View file

@ -0,0 +1,22 @@
"""e2e test to test chrome application inside docker-android"""
from unittest import TestCase
from appium import webdriver
class TestE2EChrome(TestCase):
def setUp(self):
desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',
'appPackage': 'com.android.chrome',
'appActivity': 'com.google.android.apps.chrome.Main'
}
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def test_open_url(self):
self.driver.get('http://google.com')
def tearDown(self):
self.driver.quit()

View file

View file

@ -0,0 +1,54 @@
"""Unit test to test app."""
import os
from unittest import TestCase
import mock
from src import app
class TestApp(TestCase):
"""Unit test class to test other methods in the app."""
def test_valid_env(self):
key = 'ENV_1'
os.environ[key] = 'test'
app.get_or_raise(key)
del os.environ[key]
def test_invalid_env(self):
with self.assertRaises(RuntimeError):
app.get_or_raise('ENV_2')
def test_valid_bool(self):
self.assertEqual(app.convert_str_to_bool('True'), True)
self.assertEqual(app.convert_str_to_bool('t'), True)
self.assertEqual(app.convert_str_to_bool('1'), True)
self.assertEqual(app.convert_str_to_bool('YES'), True)
def test_invalid_bool(self):
self.assertEqual(app.convert_str_to_bool(''), False)
self.assertEqual(app.convert_str_to_bool('test'), False)
def test_invalid_format(self):
self.assertEqual(app.convert_str_to_bool(True), None)
@mock.patch('src.app.prepare_avd')
@mock.patch('subprocess.Popen')
def test_run_with_appium(self, mocked_avd, mocked_subprocess):
with mock.patch('src.app.appium_run') as mocked_appium:
os.environ['APPIUM'] = str(True)
app.run()
self.assertTrue(mocked_avd.called)
self.assertTrue(mocked_subprocess.called)
self.assertTrue(mocked_appium.called)
@mock.patch('src.app.prepare_avd')
@mock.patch('subprocess.Popen')
def test_run_withhout_appium(self, mocked_avd, mocked_subprocess):
with mock.patch('src.app.appium_run') as mocked_appium:
os.environ['APPIUM'] = str(False)
app.run()
self.assertTrue(mocked_avd.called)
self.assertTrue(mocked_subprocess.called)
self.assertFalse(mocked_appium.called)