Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Android Building, Testing and reversing
1.
2. Agenda:
-Intro
-Android Testing
-Creating a project
-JUnit Testing
-Mock Objects + UI Testing
-Integration and acceptance test
-Performance and system testing
-Advance assertions
-TDD
-Real App Dev
!
25. Android Testing
Best practice: test should live in a separate
correlated project
• Stripped (not included in main)
• Easier to run in Emulator
• Takes less time
• Encourages code reusability
44. Benchmarking
• Traditional logging statement methods
• Creating Android performance tests
• Using profiling tools
• Microbenchmarks using Caliper
45. Benchmarking
/* (non-Javadoc)
* @see android.text.TextWatcher#onTextChanged(
* java.lang.CharSequence, int, int, int)
*/
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if (!mDest.hasWindowFocus() || mDest.hasFocus() ||
s == null ) {
return; }
final String str = s.toString();
if ( "".equals(str) ) {
mDest.setText("");
return;
}
final long t0;
if ( BENCHMARK_TEMPERATURE_CONVERSION ) {
t0 = System.currentTimeMillis();
}
!
46. Benchmarking
try {
final double temp = Double.parseDouble(str);
final double result = (mOp == OP.C2F) ?
TemperatureConverter.celsiusToFarenheit(temp);
TemperatureConverter.fahrenheitToCelsius(temp);
final String resultString = String.format("%.2f", result);
mDest.setNumber(result);
mDest.setSelection(resultString.length());
} catch (NumberFormatException e) {
// WARNING
// this is generated while a number is entered,
// for example just a '-'
// so we don't want to show the error
} catch (Exception e) {
mSource.setError("ERROR: " + e.getLocalizedMessage());
}
if ( BENCHMARK_TEMPERATURE_CONVERSION ) {
long t = System.currentTimeMillis() - t0;
Log.i(TAG, "TemperatureConversion took " + t +
" ms to complete.");
}
}
50. Assertions in depth
}
public void testShouldThrowException() {
try {
MyFirstProjectActivity.methodThatShouldThrowException();
fail("Exception was not thrown");
} catch ( Exception ex ) {
// do nothing
}
51. Custom messages
public void testMax() {
final int a = 1;
final int b = 2;
final int expected = b;
final int actual = Math.max(a, b);
assertEquals("Expection " + expected + " but was " + actual,
expected, actual);
}
52. Static imports
public void testAlignment() {
final int margin = 0;
...
android.test.ViewAsserts.assertRightAligned(
mMessage, mCapitalize, margin);
!
}
53. Static imports
import static android.test.ViewAsserts.assertRightAligned;
public void testAlignment() {
final int margin = 0;
assertRightAligned(mMessage, mCapitalize, margin);
}
91. Requirements:
• Application convert from Celsius to F.
• … and viceversa
• Two fields to input data
• When temperature is entered, other field updates
• Error displayed
• Some space reserved keyboard
• Entry fields start empty
• Digits right aligned
• Last entered values retained after onPause()