Skip to content

Commit fc4caa1

Browse files
committed
First test working and the first activity created
1 parent f8fe196 commit fc4caa1

File tree

9 files changed

+138
-3
lines changed

9 files changed

+138
-3
lines changed

app/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@ android {
2121
}
2222
}
2323

24+
//https://developer.android.com/training/testing/set-up-project
25+
// useLibrary 'android.test.runner'
26+
// useLibrary 'android.test.base'
27+
// useLibrary 'android.test.mock'
28+
2429
}
2530

2631
dependencies {
2732
implementation fileTree(dir: 'libs', include: ['*.jar'])
28-
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
33+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2934
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
35+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
36+
implementation 'com.android.support:design:28.0.0-rc02'
3037
testImplementation 'junit:junit:4.12'
3138

3239
androidTestImplementation 'com.android.support.test:runner:1.0.2'
40+
androidTestImplementation 'com.android.support.test:rules:1.0.2'
3341
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
42+
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
43+
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
44+
3445
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cz.josefadamcik.activityjournal
2+
3+
import android.support.test.espresso.Espresso.onView
4+
import android.support.test.espresso.assertion.ViewAssertions.matches
5+
6+
import android.support.test.espresso.matcher.ViewMatchers.*
7+
import android.support.test.filters.LargeTest
8+
import android.support.test.rule.ActivityTestRule
9+
import android.support.test.runner.AndroidJUnit4
10+
import org.junit.Rule
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
14+
15+
@RunWith(AndroidJUnit4::class)
16+
@LargeTest
17+
class MainActivityTest {
18+
@Rule
19+
@JvmField
20+
var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
21+
22+
@Test
23+
fun applicationStart_activityDisplays() {
24+
onView(withId(R.id.fab))
25+
.check(matches(isDisplayed()))
26+
onView(withId(R.id.toolbar))
27+
.check(matches(isDisplayed()))
28+
}
29+
30+
}

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<manifest package="cz.josefadamcik.activityjournal"
23
xmlns:android="http://schemas.android.com/apk/res/android">
34

@@ -7,5 +8,17 @@
78
android:label="@string/app_name"
89
android:roundIcon="@mipmap/ic_launcher_round"
910
android:supportsRtl="true"
10-
android:theme="@style/AppTheme"/>
11-
</manifest>
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/title_activity_main"
15+
android:theme="@style/AppTheme.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN"/>
18+
19+
<category android:name="android.intent.category.LAUNCHER"/>
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cz.josefadamcik.activityjournal
2+
3+
import android.os.Bundle
4+
import android.support.design.widget.Snackbar
5+
import android.support.v7.app.AppCompatActivity;
6+
7+
import kotlinx.android.synthetic.main.activity_main.*
8+
9+
class MainActivity : AppCompatActivity() {
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.activity_main)
14+
setSupportActionBar(toolbar)
15+
16+
fab.setOnClickListener { view ->
17+
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
18+
.setAction("Action", null).show()
19+
}
20+
}
21+
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.design.widget.CoordinatorLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".MainActivity">
9+
10+
<android.support.design.widget.AppBarLayout
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:theme="@style/AppTheme.AppBarOverlay">
14+
15+
<android.support.v7.widget.Toolbar
16+
android:id="@+id/toolbar"
17+
android:layout_width="match_parent"
18+
android:layout_height="?attr/actionBarSize"
19+
android:background="?attr/colorPrimary"
20+
app:popupTheme="@style/AppTheme.PopupOverlay"/>
21+
22+
</android.support.design.widget.AppBarLayout>
23+
24+
<include layout="@layout/content_main"/>
25+
26+
<android.support.design.widget.FloatingActionButton
27+
android:id="@+id/fab"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_gravity="bottom|end"
31+
android:layout_margin="@dimen/fab_margin"
32+
app:srcCompat="@android:drawable/ic_dialog_email"/>
33+
34+
</android.support.design.widget.CoordinatorLayout>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
9+
tools:context=".MainActivity"
10+
tools:showIn="@layout/activity_main">
11+
12+
</android.support.constraint.ConstraintLayout>

app/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<dimen name="fab_margin">16dp</dimen>
3+
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">ActivityJournal</string>
3+
<string name="title_activity_main">MainActivity</string>
34
</resources>

app/src/main/res/values/styles.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
<item name="colorAccent">@color/colorAccent</item>
99
</style>
1010

11+
<style name="AppTheme.NoActionBar">
12+
<item name="windowActionBar">false</item>
13+
<item name="windowNoTitle">true</item>
14+
</style>
15+
16+
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
17+
18+
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
19+
1120
</resources>

0 commit comments

Comments
 (0)