mirror of
https://github.com/budtmo/docker-android.git
synced 2026-07-29 19:00:34 +00:00
Added End-2-End Test
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user