Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From an idea to your first tested app

From an idea to your first tested app

How do you start with an Android app? Which are the tools you need and the concepts you need to learn to quickly prototype someting working?What are the best tools for testing and using Continuous integration for Android?

Avatar for Chiara Chiappini

Chiara Chiappini

November 23, 2015

More Decks by Chiara Chiappini

Other Decks in Programming

Transcript

  1. From an idea to your first (tested) app Chiara Chiappini

    @chiarachiappini google.com/+chiarachiappini
  2. Android Studio official IDE for Android application development based on

    IntelliJ IDEA layout editor flexible Gradle-based build system @chiarachiappini
  3. Gradle build automation tool cross platform builds dependency management integration

    with Android Studio Gradle Wrapper to ensure everyone in the team is using the same version @chiarachiappini
  4. Layout @chiarachiappini <RelativeLayout ...> <Toolbar android:id="@+id/weather_toolbar".../> <LinearLayout android:id="@+id/weather_info_layout".../> <TextView android:id="@+id/weather_description".../>

    <TextView android:id="@+id/weather_temp".../> <View .../> <ImageView android:id="@+id/weather_icon".../> </LinearLayout </RelativeLayout >
  5. Activity protected void onCreate(Bundle savedInstanceState) { ........ toolbar = (Toolbar)

    findViewById(weather_toolbar); toolbar.setTitle("Richmond"); setSupportActionBar(toolbar); tempView =(TextView) findViewById(weather_temp); tempView.setText("15"); descriptionView = (TextView) findViewById(weather_description); descriptionView.setText("Sun is shining"); iconView = (ImageView) findViewById(weather_icon); iconView.setImageResource(R.drawable.sun);
  6. public class WeatherOracleTest { private WeatherOracle weatherOracle; @Before public void

    setup(){ weatherOracle = new WeatherOracle(); } @Test public void shouldReturnASunnyWeather(){ Weather expectedWeather = new Weather(SUN_IS_SHINING, TEMPERATURE, ICON_ID); assertEquals(expectedWeather, weatherOracle.getWeather()); } }
  7. assertEquals(expectedWeather, weatherOracle.getWeather()); } public class WeatherOracle { public static final

    String SUN_IS_SHINING = "Sun is shining"; public static final double TEMPERATURE = 15.0; public static final String ICON_ID = "sun"; public Weather getWeather() { return new Weather(SUN_IS_SHINING, TEMPERATURE, ICON_ID); } } @chiarachiappini
  8. public class WeatherIconMapperTest { private static final String A_WEATHER_DESCRIPTION =

    "aWeatherDescription"; private static final double A_WEATHER_TEMPERATURE = 15.0; private static final String SUN_ICON_ID = "sun"; @Test public void shouldReturnTheRightIconWhenSunny() throws IconNotFoundException { Weather weather = new Weather(A_WEATHER_DESCRIPTION, A_WEATHER_TEMPERATURE, SUN_ICON_ID); int expectedIcon = R.drawable.sun; assertEquals(expectedIcon, WeatherIconMapper.getIconResourceIdForWeather(weather)); } }
  9. public class WeatherIconMapper { public static int getIconResourceIdForWeather(Weather weather) throws

    IconNotFoundException { if(weather.getWeatherIconId().equals("sun")) { return R.drawable.sun; } throw new IconNotFoundException(); } } assertEquals(expectedIcon, WeatherIconMapper.getIconResourceIdForWeather(weather));
  10. @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21) public class MainActivityTest

    { @Before public void setUp() throws Exception { mainActivity = Robolectric.buildActivity(MainActivity.class).create().get(); } @Test public void testMainActivity() { assertNotNull(mainActivity.findViewById(R.id.weather_toolbar)); assertNotNull(mainActivity.findViewById(R.id.weather_description)); …. } }
  11. public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> activityRule = new

    ActivityTestRule<> (MainActivity.class); @Test public void showTemperature() { onView(withId(R.id.weather_temp)) .check(matches(withText("15"))); } @chiarachiappini
  12. Continuous Integration early feedback team peace of mind and alerting

    standardized build record of results @chiarachiappini
  13. Continuous Integration early feedback team peace of mind and alerting

    standardized build record of results support release process @chiarachiappini
  14. Continuous Integration early feedback team peace of mind and alerting

    standardized build record of results support release process first step to continuous deployment @chiarachiappini
  15. Travis free for public repositories community boxes and queues subscription

    for no waiting and concurrent jobs @chiarachiappini
  16. steps go to Travis CI sign in with GitHub user

    activate GitHub webhook @chiarachiappini
  17. steps go to Travis CI sign in with GitHub user

    activate GitHub webhook add .travis.yml to your repository @chiarachiappini