-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make instrumentation tests more independant from each other #591
Make instrumentation tests more independant from each other #591
Conversation
Some tests may require some additional or specific preferences to be set to specific values in order to work correctly. To achieve that, this commit adds a Before method to both instrumentation tests, which will set these required preferences before starting the activity. It also removes the "go through intro" from the BasicWigetTest2, which is already tested in the CheckIntroAndCancel test, so there's no need to test it again. It is also out of scope of the test case. Signed-off-by: Florian <[email protected]>
public void setup() { | ||
PreferenceManager | ||
.getDefaultSharedPreferences(InstrumentationRegistry.getTargetContext()) | ||
.edit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried first calling clear() here. However, even if it works perfectly fine for the first test run, during the second test run, the preferences are resetted to the default values and the ones I set next are applied, however, the app behaves weird when started:
- The theme is dark, not light, even though that light is selected in the preferences
- the discovery of the openHAB server is started, even though Demo mode is enabled in the preferences
- The app says, that I should check, if openHAB is running
Opening the settings and just going back will result in the expected behaviour (light theme, demo mode, sitemap selection). I've no idea why this happens, however it does not happen when not using clear().
This may not be important for the tests in travis, as uninstalling the app before running the test again also works (and travis should always install on a clean emulator), however, I don't think that it will help us as developers :)
|
||
@Test | ||
public void openHABMainActivityTest2() throws InterruptedException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "2" was introduced by me, when I capture it via Android Studio. Can you remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 :)
CheckIntroAndCancel cancels the intro, BasicWigetTest2 goes throught the intro. |
.getDefaultSharedPreferences(InstrumentationRegistry.getTargetContext()) | ||
.edit() | ||
.putString(Constants.PREFERENCE_SITEMAP, "") | ||
.putBoolean(Constants.PREFERENCE_FIRST_START, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also enable demo mode. Its disabled by default in #562
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move both tests for the intro into their own test class then, ok? |
IntroActivityTest is the "old" CheckIntroAndCancel test class. It now holds both test case, which tests the intro activity. Signed-off-by: Florian <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
#526 still failing |
Some tests may require some additional or specific preferences to be set
to specific values in order to work correctly.
To achieve that, this commit adds a Before method to both instrumentation
tests, which will set these required preferences before starting the
activity. It also removes the "go through intro" from the BasicWigetTest2,
which is already tested in the CheckIntroAndCancel test, so there's no
need to test it again. It is also out of scope of the test case.