How to check Toolbar title in android instrumental test?
Tag : java , By : Cube_Zombie
Date : March 29 2020, 07:55 AM
this will help SOLUTION The method is fine. As Chiu-Ki Chan wrote in her tutorial you can "pinpoint that one particular view". BUT you have to make sure you imported proper Toolbar: import android.support.v7.widget.Toolbar;
import android.widget.Toolbar;
|
How to put test data files on a device for instrumental tests?
Date : March 29 2020, 07:55 AM
Hope that helps I found the following way to do that: Create some test class which is responsible for initialization and must be ran first. To run tests in particular order I'm using the Suite class like this one: @RunWith(Suite.class)
@Suite.SuiteClasses({TestEnvironmentInitializer.class,
FirstTest.class,
SecondTest.class
})
public class MyTestSuite {
}
./gradlew yourappmodule:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=your.package.androidtest.MyTestSuite
./gradlew yourappmodule:connectedStagingAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=your.package.androidtest.MyTestSuite
@Rule
public GrantPermissionRule runtimePermissionRule = GrantPermissionRule.grant(
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestEnvironmentInitializer {
@Rule
public GrantPermissionRule runtimePermissionRule = GrantPermissionRule.grant(
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
public void initEnvironment() {
try {
Context testContext = InstrumentationRegistry.getInstrumentation().getContext();
File root = Environment.getExternalStorageDirectory();
File testDataFolder = new File(root, "testData");
if(testDataFolder.mkdirs()) {
File destFile = new File(testDataFolder, "test_data.dat");
if (!destFile.exists()) {
copyAssetToExternalStorage(testContext, "assetssubfolder/test_data.dat", destFile);
}
}
} catch (Throwable e) {
System.exit(-1);
}
}
void copyAssetToExternalStorage(Context context, String fileToCopy, File dest) throws
IOException {
try (InputStream src = context.getAssets().open(fileToCopy)) {
try (FileOutputStream destStream = new FileOutputStream(
dest)) {
copyStream(src, destStream);
}
}
}
void copyStream(InputStream src, OutputStream dest) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = src.read(buffer)) != -1) {
dest.write(buffer, 0, read);
}
}
}
|
How to log or print in Android Instrumental Test
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further In Android app, we could log out using , Just use the normal Log.d(TAG, message)
|
In which AndroidX library is the androidx.test.annotation package located?
Tag : android , By : Bart van Bragt
Date : March 29 2020, 07:55 AM
Hope this helps Simple question: , It is in androidx.test:rules: androidTestImplementation 'androidx.test:rules:1.2.0'
|
Simple MVVM architecture on Android with AndroidX on Java
Tag : java , By : dlouzan
Date : March 29 2020, 07:55 AM
I hope this helps you . I figure that I was not binding correctly the ViewModel from the Activity: public class DataActivity extends AppCompatActivity {
private DataViewModel mViewModel;
private DataActivityBinding mBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.mViewModel = new DataViewModel();
this.mBinding = DataBindingUtil.setContentView(this, R.layout.data_activity);
this.mBinding.setViewModel(this.mViewModel);
}
}
|