Android app fundamentals 1.0

sunil gaurav
SGTesterNotes
Published in
3 min readAug 17, 2020

--

I explored various android projects and got to learn a lot from that . Playing around with an android app is fun but the real fun to me is understanding what goes inside making an app . This blog would help beginners to understand a bit about Android application , project structure , Testing etc.

The topmost language used to develop an Android app are Kotlin and Java . Still Java apps are more in number however Kotlin is rising rapidly .

The Android SDK complies the code and resources into an APK file

Android Project Structure —

Above screenshot shows the default android project structure . Let’s discuss a bit about the project wide files -

  • .idea directory contains Intellij IDEA settings.
  • .gitignore file specifies which files/directories to be ignored by Git
  • gradle directory contains gradle-wrapper files.
  • build.gradle allows you to customise properties for build system such as setting location of your keystore used for signing the app-release.apk.
  • settings.gradle tells sub-projects for gradle to build.

Now let’s switch to the contents of the app folder –

src/main/java package contain the source code of the project

Under same package we have the Android manifest file . It is a must have for all android application . This tells us about the nature of the application . It contains the name, icon of the application . It also lets you know the various activities of the app , permissions etc for the app

<?xml version=”1.0" encoding=”utf-8"?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android"
package=”com.oreilly.helloandroidjava”>

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
</manifest>

Test folder : This folder is created by default when you create an Android project . This should contain the Unit tests for the code .As the name suggests unit testing is used to test the logic on the individual unit of the code . In the below example we have method isValidEmail() in the AUT which verifies the email provided . So in the Unit test(written as JUNIT test) we test that method’s output by passing some email i.e we test the logic on that unit of code -

import com.google.common.truth.Truth.assertThat;
import org.junit.Test;

public class EmailValidatorTest {
@Test
public void emailValidator_CorrectEmailSimple_ReturnsTrue() {
assertThat(EmailValidator.isValidEmail(“name@email.com”)).isTrue();
}
}

Android Unit tests reside in test folder

AndroidTest folder : This folder is created by default when you create an Android project . This should contain the UI tests for the application. This is the best way to test how the app handles user’s interaction . Espresso and UI automator can be used to write these tests . Espresso has a cool feature of Recording the tests which can be then played back. I would cover more on the UI testing in upcoming blog.

Android UI tests reside in androidTest folder

--

--