Skip to content
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

Merged
merged 2 commits into from
Jan 1, 2018

Conversation

FlorianSW
Copy link
Member

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.

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]>
@mueller-ma mueller-ma self-requested a review January 1, 2018 19:42
@mueller-ma mueller-ma added the code enhancement Indicates code improvements label Jan 1, 2018
public void setup() {
PreferenceManager
.getDefaultSharedPreferences(InstrumentationRegistry.getTargetContext())
.edit()
Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 :)

@mueller-ma
Copy link
Member

CheckIntroAndCancel cancels the intro, BasicWigetTest2 goes throught the intro.

.getDefaultSharedPreferences(InstrumentationRegistry.getTargetContext())
.edit()
.putString(Constants.PREFERENCE_SITEMAP, "")
.putBoolean(Constants.PREFERENCE_FIRST_START, false)
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it in #562 if this PR is merge before it, or otherwise add it once #562 is merged, ok? Doing that keeps both PRs clean I think :]

@FlorianSW
Copy link
Member Author

CheckIntroAndCancel cancels the intro, BasicWigetTest2 goes throught the intro.

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]>
Copy link
Member

@mueller-ma mueller-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mueller-ma mueller-ma merged commit bb45fce into openhab:master Jan 1, 2018
@mueller-ma
Copy link
Member

#526 still failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code enhancement Indicates code improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants