Skip to content

Commit

Permalink
Refactored Espresso tests and forced english language for all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Feb 9, 2020
1 parent 272a6e3 commit 389fb4c
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 320 deletions.
2 changes: 1 addition & 1 deletion omniNotes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ android.productFlavors.each { flavor ->
apply plugin: 'jacoco-android'
jacocoAndroidUnitTestReport {
csv.enabled false
html.enabled true
html.enabled false
xml.enabled true
}
jacoco {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

package it.feio.android.omninotes;

import static org.junit.Assert.assertFalse;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.RECORD_AUDIO;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static java.util.Locale.ENGLISH;

import android.Manifest;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;
import it.feio.android.omninotes.db.DbHelper;
import it.feio.android.omninotes.helpers.LanguageHelper;
import it.feio.android.omninotes.utils.Constants;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand All @@ -42,22 +47,20 @@ public class BaseAndroidTestCase {

@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, RECORD_AUDIO
);

@BeforeClass
public static void setUpBeforeClass () {
testContext = ApplicationProvider.getApplicationContext();
testContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
prefs = testContext.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS);
dbHelper = DbHelper.getInstance(testContext);
prefs = testContext.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE);
// assertTrue("Database used for tests MUST not be the default one but prefixed by '" + DB_PREFIX + "'", dbHelper
// .getDatabase().getPath().matches(DB_PATH_REGEX));
// assertFalse("Database MUST be writable", dbHelper.getDatabase(true).isReadOnly());
// cleanDatabase();
LanguageHelper.updateLanguage(testContext, ENGLISH.toString());
}

@AfterClass
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes;
package it.feio.android.omninotes.ui;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
Expand All @@ -37,8 +37,10 @@
import static org.junit.Assert.assertTrue;

import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.filters.LargeTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.helpers.BackupHelper;
import it.feio.android.omninotes.models.Note;
import it.feio.android.omninotes.utils.Constants;
Expand Down Expand Up @@ -112,7 +114,7 @@ public void everyUpdateToNotesShouldTriggerAutobackup () throws InterruptedExcep

// Category addition

onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click());
onData(anything()).inAdapterView(ViewMatchers.withId(R.id.list)).atPosition(0).perform(click());

onView(allOf(withId(R.id.menu_category), withContentDescription(R.string.category),
childAtPosition(
Expand Down
Loading

0 comments on commit 389fb4c

Please sign in to comment.