-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Unit tests for AndroidProject and Builders #458
Conversation
Thanks for the tests! I'll review them as soon as I find time. Please take a look at #437. These two Builders also bothered me to the point that I wanted to refactor them but thankfully we might be able to get rid of one. Maybe @jcesarmobile can provide you with more details in case you want to tackle this. |
Also note the test failures on windows due to unexpected path separators. |
65cbe69
to
d76aff8
Compare
Whoops, those failing Windows tests should be fixed now. I was wondering about the different builders and how they are used, thanks for linking that issue. I'll dig deeper and see what I can do. |
Codecov Report
@@ Coverage Diff @@
## master #458 +/- ##
==========================================
+ Coverage 52.03% 54.75% +2.71%
==========================================
Files 17 18 +1
Lines 1695 1852 +157
Branches 312 333 +21
==========================================
+ Hits 882 1014 +132
- Misses 813 838 +25
Continue to review full report at Codecov.
|
I'm not really sure what the GradleBuilder is for, it was probably used before we had the StudioBuilder to build Eclipse Gradle projects, as Eclipse projects could be built with Ant or Gradle. According to a Joe's comment on this PR, it's not used now that we only have Android Studio projects #437, so should be safe to delete. All Android Studio projects are Gradle projects, that's probably why the GradleBuilder and StudioBuilder are similar. |
@jcesarmobile Because of this fact I thought that we should name the remaining builder GradleBuilder. Especially if it might also be used to build non-Studio projects. Does that make sense? |
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.
First commit LGTM. Great tests as usual ❤️
spec/unit/AndroidProject.spec.js
Outdated
}); | ||
|
||
describe('constructor', () => { | ||
it('should set the project directory and www folder', () => { |
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.
This tests only the first part, right?
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.
Ah yes, you're right. It originally tested project.www
but I ended up breaking those into separate tests and forgot to rename this one.
spec/unit/AndroidProject.spec.js
Outdated
expect(newProject).toEqual(jasmine.any(AndroidProject)); | ||
}); | ||
|
||
it('should return the existing project', () => { |
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.
Maybe "should cache created projects"?
|
||
const cache = AndroidProject.__get__('projectFileCache'); | ||
expect(Object.keys(cache).length).toBe(2); | ||
expect(cache[projectToRemove]).toBe(undefined); |
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 find in
to be vastly underused in the JS community 😉
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.
Yeah, it wouldn't even cross my mind to use it!
spec/unit/AndroidProject.spec.js
Outdated
@@ -113,15 +113,15 @@ describe('AndroidProject', () => { | |||
|
|||
androidProject.getPackageName(); | |||
|
|||
expect(AndroidManifestSpy).toHaveBeenCalledWith(`${PROJECT_DIR}/AndroidManifest.xml`); | |||
expect(AndroidManifestSpy).toHaveBeenCalledWith(path.join(PROJECT_DIR, 'AndroidManifest.xml')); |
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.
That should go into the first commit
All Cordova projects are Android Studio projects. That just means that you can open them in Android Studio without problems and they will work if you run from there. We are not going to build projects that are not compatible with Android Studio. But as Android Studio projects are also Gradle projects, you don't need to open Android Studio to build them. About the naming, I don't care much if we keep StudioBuilder or we keep the GradleBuilder and move Android Studio stuff there. |
So one could rename the AndroidBuilder.js to e.g. ProjectBuilder.js, integrate GenericBuilder.js and clean the code to match this? |
@janpio I like ProjectBuilder. Future proof naming for whatever Google throws at us 😄 |
Thanks for all your feedback. It sounds like all the three builders could be made in to one. At that point do we still need If it's not needed, then all of these files could be brought into a single file ( As for the testing, I mentioned that I would like to fully cover the builders, but I don't have a good |
I am working on refactoring the builders now. Since most of these tests will be outdated once that is done, I am going to close this PR. Later I will create a new PR with the builders refactor (and the appropriate unit tests). As for the tests unrelated to the builders in this PR, I will also submit them separately. |
<!-- Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines: http://cordova.apache.org/contribute/contribute_guidelines.html Thanks! --> ### Platforms affected Android ### What does this PR do? This is the last unit test PR for today, I promise! The `AndroidProject` tests were originally in #458. This PR also contains increased test coverage for `android_sdk.js`. I have also refactored that to remove `Q`, as with the other PRs I submitted today. ### What testing has been done on this change? Run unit tests ### Checklist - [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database - [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. - [x] Added automated test coverage as appropriate for this change.
Platforms affected
Android unit tests
What does this PR do?
I have written some more unit tests to continue increasing the coverage. This brings coverage to 54.94%. The coverage didn't increase as much as expected, as one of the files I have now written tests for (
GenericBuilder.js
) was not included at all in the previous coverage reports.Unlike my previous tests, none of the files I have covered this time have reached 100%. This is because they are processing configuration files which I do not have good example of for testing. The main file I need a good example of is
project.properties
, with various entries. If there is one I could use, I am happy to complete the test coverage for these files.Another thing to note is that
GradleBuilder.js
andStudioBuilder.js
are very similar files, so the tests are pretty much copy-pasted.GenericBuilder.js
appears to exist to pull out some functionality shared between the two, but it could definitely contain more. In a future PR, once I have complete test coverage of these files, I would like to break out the common code to make it more maintainable.What testing has been done on this change?
Locally run
npm run unit-tests
Checklist