Stanislav Gatsev presents on unit and automation testing on Android. He discusses why automation testing is important for saving time, improving code quality, and supporting live documentation. He covers using JUnit and Mockito for testing, as well as activity testing with ActivityInstrumentationTestCase2 and user interface testing with Robotium. Mock objects are used to replace dependencies and allow testing in isolation. Examples are provided of writing unit tests, activity tests, and tests using Robotium to simulate user interactions.
V1.0
How often do you get a bug report that you can’t reproduce?
How often do you struggle to find the source of the bug in your code?
How can you streamline the testing process and make sure you don’t repeat the same bugs?
With Visual Studio 2010 & Team Foundation Server (TFS) 2010 there are a lot of new features for testers and developers that will solve these problems.
In this session you will learn how to: automate more, reproduce bugs easier, maintain your tests and configuration and discover problems sooner.
from Peter Gfader
Step by step introduction to get unit testing, UI testing, mocking and continuous integration up and running for your Swift projects. These slides are from Agile Swift Meetup in Montreal.
V1.0
How often do you get a bug report that you can’t reproduce?
How often do you struggle to find the source of the bug in your code?
How can you streamline the testing process and make sure you don’t repeat the same bugs?
With Visual Studio 2010 & Team Foundation Server (TFS) 2010 there are a lot of new features for testers and developers that will solve these problems.
In this session you will learn how to: automate more, reproduce bugs easier, maintain your tests and configuration and discover problems sooner.
from Peter Gfader
Step by step introduction to get unit testing, UI testing, mocking and continuous integration up and running for your Swift projects. These slides are from Agile Swift Meetup in Montreal.
Guide to the jungle of testing frameworksTomáš Kypta
There are many tools, libraries and frameworks available for Android developers to test their applications. The jungle is huge and it's not easy to find the right ones. Some frameworks are good for unit testing, some are good for instrumentation testing, and some can be used for both. Some have great capabilities but annoying weaknesses. Some are good for testing UI, other allow you to make good mocks. We will look at many frameworks, the popular ones like Mockito, Robolectric, Espresso, and some other.
Presented at GDG DevFest Minsk 2016.
Alexey Buzdin "Maslow's Pyramid of Android Testing"IT Event
You all know what tests are. You all know you need to write them. But also you know it’s hard to start writing tests for mobile app thus you usually neglect it. Let’s look into Android automation testing, what technologies and approaches we can use to have a complete Maslow's Pyramid for testing. Unit Testing, Integration Testing, UI Automation, Mocking etc.
Automating Tactically vs Strategically SauceCon 2020Alan Richardson
One of the biggest concepts that has made a difference to my programming and automating in recent years is the concept of “Tactical vs. Strategic.” Automating tactically might be for a specific purpose, possibly small, possibly a bit rough around the edges, not necessarily completely robust for everyone, etc. And Strategic automation is more critical to long-term aims, maintained and maintainable, etc.
In this talk, Alan Richardson will provide examples of automating both Strategically and Tactically for activities as diverse as supporting testing, marketing and general life. We will also consider how and when to move from automating tactically to strategically, and how the concept has helped me change my programming style and how to write better code.
This presentation describes the some of the major functionality of JUnit4 and TestNG .Each topic contains example so that a viewer can understand the usage and apply them in their code.
Testing Java Microservices Devoxx be 2017Alex Soto
With traditional software unit tests, there's never a guarantee that an application will actually function correctly in the production environment. And when you add microservices, remote resources that are accessible over a network, into the mix, testing is more tricky. To make things even harder, microservices typically need to collaborate with additional network-based microservices, making testing even more challenging.
In this session you'll learn test strategies that solve the most common issues you are likely to encounter when writing tests for microservices architecture. Also you'll learn how tools such as Arquillian, JUnit, Docker or techniques suck as service virtualization or consumer-driven testing can help you on this task.
This presentation, created by Syed Faiz ul Hassan, explores the profound influence of media on public perception and behavior. It delves into the evolution of media from oral traditions to modern digital and social media platforms. Key topics include the role of media in information propagation, socialization, crisis awareness, globalization, and education. The presentation also examines media influence through agenda setting, propaganda, and manipulative techniques used by advertisers and marketers. Furthermore, it highlights the impact of surveillance enabled by media technologies on personal behavior and preferences. Through this comprehensive overview, the presentation aims to shed light on how media shapes collective consciousness and public opinion.
Acorn Recovery: Restore IT infra within minutesIP ServerOne
Introducing Acorn Recovery as a Service, a simple, fast, and secure managed disaster recovery (DRaaS) by IP ServerOne. A DR solution that helps restore your IT infra within minutes.
0x01 - Newton's Third Law: Static vs. Dynamic AbusersOWASP Beja
f you offer a service on the web, odds are that someone will abuse it. Be it an API, a SaaS, a PaaS, or even a static website, someone somewhere will try to figure out a way to use it to their own needs. In this talk we'll compare measures that are effective against static attackers and how to battle a dynamic attacker who adapts to your counter-measures.
About the Speaker
===============
Diogo Sousa, Engineering Manager @ Canonical
An opinionated individual with an interest in cryptography and its intersection with secure software development.
This presentation by Morris Kleiner (University of Minnesota), was made during the discussion “Competition and Regulation in Professions and Occupations” held at the Working Party No. 2 on Competition and Regulation on 10 June 2024. More papers and presentations on the topic can be found out at oe.cd/crps.
This presentation was uploaded with the author’s consent.
2. Who am I?
Stanislav Gatsev
Android Team Lead
+359 89 891 4481
stanislav.gatsev@melontech.com
http://www.melon.bg
3. What is Android?
o World's most popular mobile
platform
o Every day another million users
power up their Android devices for
the first time
o Using Android SDK we can develop
software for almost everything from
smartphones and tablets to
glasses, watches, TVs and even
cars.
4. Why we automate testing?
o We save time !!!
o We improve our code quality
o We support live documentation
o We run our regression tests
o We fight fragmentation
6. What Can We Test?
o We can test our logic, algorithms, calculations
o We can test our UI and navigation logic
o We can test IO operations, database and network
operations
o And more...
@SmallTest
public void test_addOperatorInJava() throws Exception {
Assert.assertEquals(4, 2 + 2);
Assert.assertEquals(27, 25 + 2);
}
@SmallTest
public void test_FieldsAreVisible() {
ViewAsserts.assertOnScreen(mRootView, mEmailEditText);
ViewAsserts.assertOnScreen(mRootView, mPasswordEditText);
ViewAsserts.assertOnScreen(mRootView, mLoginActionLayout);
}
7. How we automate testing?
o We use JUnit
o We mock our objects
o We are using activity testing framework
o We click with Robotium
8. JUnit and Android
We can use the JUnit TestCase class to do unit testing on a class that
doesn't call Android APIs. TestCase is also the base class for
AndroidTestCase, which we can use to test Android-dependent objects.
Besides providing the JUnit framework, AndroidTestCase offers
Android-specific setup, teardown, and helper methods.
public class UtilTests extends AndroidTestCase {
@SmallTest
public void test_StringToLatLngValidValues() throws Exception {
String latLngString = "34.009555,-118.497072";
LatLng latLng = Util.stringToLatLng(latLngString);
Assert.assertEquals(Double.compare(latLng.latitude, 34.009555), 0);
Assert.assertEquals(Double.compare(latLng.longitude, -118.497072), 0);
}
@SmallTest
public void test_StringToLatLngValidInvalues() throws Exception {
String latLngString = "34.009555,-a118.497072";
LatLng latLng = Util.stringToLatLng(latLngString);
Assert.assertEquals(Double.compare(latLng.latitude, 0), 0);
Assert.assertEquals(Double.compare(latLng.longitude, 0), 0);
}
}
9. Why we use Mocks?
The objective of unit testing is to exercise just one method at a time, but what
happens when that method depends on other things—hard-to-control things
such as the network, or a database.
The solution is the Mock object. It is simply a debug replacement for a real-
world object.
10. Mockito
Mockito is the way we mock objects in Android. As its developers say:
“Mockito is a mocking framework that tastes really good. It lets you write
beautiful tests with clean & simple API. Mockito doesn't give you hangover
because the tests are very readable and they produce clean verification
errors.”
• https://code.google.com/p/dexmaker/
• System property hack
11. Mockito and Android
//create Mock of server communication
final WeatherServerRequest weatherServerRequest =
Mockito.mock(WeatherServerRequest.class);
//stub the actual network call and return empty object
ServerResponse serverResponse = new ServerResponse();
Mockito.when(weatherServerRequest.getResponse()).thenReturn(serverResponse);
//create mock of the refresh-able and the observers subject
IRefreshable refreshable = Mockito.mock(IRefreshable.class);
ISubject subject = Mockito.mock(ISubject.class);
runWeatherWorkerThread(refreshable, subject, weatherServerRequest);
//verify if refresh-able start callback is called
Mockito.verify(refreshable).onStartRefresh();
//verify if the observers callback is called
Mockito.verify(subject).updateData(Mockito.anyMapOf(String.class,
ServerResponse.class));
//verify if refresh-able end callback is called
Mockito.verify(refreshable).onEndRefresh();
=+
12. Activity tests
ActivityInstrumentationTestCase2
This is the class which helps us test our Activities. It has direct reference to the
tested activity and you have the ability to run whole test or just parts of it in the
UI Thread.
@SmallTest
public void test_viewPagerHasAllLocations() throws Throwable {
//Creates the data fetcher mock and injects it to the Activity for every test
createDataFetcherMock();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
//reinitialize activity with new data fetcher
getActivity().init();
}
});
//asserts if the view pager has the same number of items the data fetcher returned
Assert.assertEquals(3, mViewPager.getAdapter().getCount());
}
13. Robotium
o It is a lot easier to write our automation tests
o Helpful API for executing user actions
o Flexible results assertion
o Hybrid apps are supported
o We can use it in our Activity tests
14. Robotium in action
@LargeTest
public void test_addNewLocation() throws Throwable {
getInstrumentation().waitForIdleSync();
moveMapToPosition();
getInstrumentation().waitForIdleSync();
//gets the root view of the Activity
View rootView = getActivity().findViewById(android.R.id.content);
//long click in the center of the screen
mSolo.clickLongOnScreen(rootView.getWidth()/2, rootView.getHeight()/2);
getInstrumentation().waitForIdleSync();
//get first weather location
WeatherDataFetcher dataFetcher = getActivity().getDataFetcher();
List<WeatherLocation> weatherLocations = dataFetcher.getLocationsList();
Assert.assertEquals(1, weatherLocations.size());
//check if the location is the right one
WeatherLocation weatherLocation = weatherLocations.get(0);
Assert.assertEquals("Santa Monica, CA", weatherLocation.getLocationName());
//clears DB
dataFetcher.removeLocation(0);
}
16. References
o https://developer.android.com
o https://code.google.com/p/robotium/
o https://github.com/mockito/mockito
o http://blog.gfader.com/2010/10/why-are-automated-tests-so-important.html
o http://media.pragprog.com/titles/utj/mockobjects.pdf
o http://www.embedded.com/design/prototyping-and-
development/4398723/The-mock-object-approach-to-test-driven-
development