I'm finally getting around to trying out a few different libraries that claim to make testing Android apps easier. First up is Robolectric.
For this quick walkthrough, I'm going to show how to start from scratch. You'll need no prior knowledge except for how to make a regular Android app.
In my GitHub repo: How to get started with Robolectric
~ Danial Goodwin ~
Showing posts with label test. Show all posts
Showing posts with label test. Show all posts
2015-03-02
2014-12-06
Level Up - Android Dev: The default emulator is horrendously slow, use Genymotion!
Many years back when I built and published my first Android apps, I only tested them on the default emulator provided by Google. And, even now, the default emulator is still too slow for my liking. It doesn't allow me to properly test apps. So, I purchased physical devices so that I would never have to touch the Android emulator again.
Genymotion provides a different take on the Android emulator. I've known about it for at least a year, but never got around to trying it because of my really bad experience with the default emulator. I've always heard that it was much faster than Google's implementation, but I didn't think an Android emulator could ever be fast enough for me compared to my physical devices.
I'm always learning something new, and today was finally time for me to learn more about Genymotion and test just how much better it is.
Results: Excellent! So much of a great experience that I had to write this blog post about it! I should have tried Genymotion when I first heard about it, and this is my message to all Android devs to also try it out now!
Sidenote: I was going to compare the default emulator with the Genymotion emulator side-by-side, but it was taking too long to load for me, whereas Genymotion startup was a breeze of fresh air. It runs without any lag. It runs faster than my old API 17 device.
Another great benefit is that Genymotion provides system images for many of the most popular devices, including Samsung Galaxy, Samsung Note, HTC One, Nexus, and more. And, they have a very convenient plugin for Android Studio to launch the emulator.
TLDR: It's fast. I have to make sure I stress that because I didn't believe how fast it would be. Genymotion's Android emulator is much faster and better experience than the default Android emulator.
Here, I even saved enough time to write a quick walkthrough for getting started. ;)
Genymotion provides a different take on the Android emulator. I've known about it for at least a year, but never got around to trying it because of my really bad experience with the default emulator. I've always heard that it was much faster than Google's implementation, but I didn't think an Android emulator could ever be fast enough for me compared to my physical devices.
I'm always learning something new, and today was finally time for me to learn more about Genymotion and test just how much better it is.
Results: Excellent! So much of a great experience that I had to write this blog post about it! I should have tried Genymotion when I first heard about it, and this is my message to all Android devs to also try it out now!
Sidenote: I was going to compare the default emulator with the Genymotion emulator side-by-side, but it was taking too long to load for me, whereas Genymotion startup was a breeze of fresh air. It runs without any lag. It runs faster than my old API 17 device.
Another great benefit is that Genymotion provides system images for many of the most popular devices, including Samsung Galaxy, Samsung Note, HTC One, Nexus, and more. And, they have a very convenient plugin for Android Studio to launch the emulator.
TLDR: It's fast. I have to make sure I stress that because I didn't believe how fast it would be. Genymotion's Android emulator is much faster and better experience than the default Android emulator.
Here, I even saved enough time to write a quick walkthrough for getting started. ;)
- Go to Genymotion.com, click "Get Genymotion".
- Download the free version, you'll have to sign up and confirm your email. (It's quick and it's worth it!)
- Install it along with VirtualBox. For Windows users, they can bundle the two together in the download. For other, you'll have to install VirtualBox separately.
- If you try to run it now, you might get an error that says "genymotion virtualization engine not found. Unable to load VirtualBox engine". So, just restart your computer and that fixed it for me. Some others had to enable the virtualization feature in the BIOS.
- Run! Fast!
- Now, you can click run in Android Studio and you will see an option to load the app in the Genymotion emulator that is running.
Bonus: How to Install the Genymotion Plugin for Android Studio (and, the first time you click on the installed plugin button, you'll have to add the path to where you installed it. Windows default is "C:\Program Files\Genymobile\Genymotion". Mac default is "/Applications/Genymotion.app")
~ Danial Goodwin ~
2014-08-30
Level Up - Android: Speed up your Gradle build times with one-line!
Whether or not you are using Android Studio, Gradle build times are slow (especially when you don't have continuous automated builds (another discussion)).
Here's one way to improve the speed Gradle commands like `assembleRelease` is to enable the Gradle daemon. I've sped up my release builds by about 20%!
Here's one way to improve the speed Gradle commands like `assembleRelease` is to enable the Gradle daemon. I've sped up my release builds by about 20%!
2014-08-18
Level Up - Android: How to get started with Unit Testing in Android Studio
Recently, I finally got around to implementing the native unit testing that is provided within Android Studio (not third-party programs like Robolectric). So, after reading a few different sources, the following is the bare minimum that I would have needed in order to add the basic testing features.
2014-06-18
Level Up - Dev: Integer Overflow Not Overflowing
An integer overflow (or wraparound) occurs when a number larger than the max integer value or smaller than the min integer value is tried to be stored in the integer's memory. You could imagine a circular number line.
Ex: If you have an integer at the max positive value and add one, then the integer will wraparound and be set to the most negative value (if using a signed int. An unsigned int will wraparound to 0). And, vise-versa.
Today, I experienced a bug where I wanted to get a (signed) integer overflow, but unfortunately the int value was just going to zero instead of going to the negative numbers. Thankfully, I knew the memory/bit representation of int and was able to figure out what was going on.
Here is some simplified code, with only one small change:
// Test #1 - has wraparound
int wrap = 1;
for (int i = 0; i < 34; i++) {
print(i + ": wrap: " + wrap);
wrap = wrap * 3;
}
// Test #2 - no wraparound
int wrap = 1;
for (int i = 0; i < 34; i++) {
print(i + ": wrap: " + wrap);
wrap = wrap * 2;
}
Here is the relevant output from running the code above:
// Test #1 - has wraparound
...
13: wrap: 1594323
14: wrap: 4782969
15: wrap: 14348907
16: wrap: 43046721
17: wrap: 129140163
18: wrap: 387420489
19: wrap: 1162261467
20: wrap: -808182895
21: wrap: 1870418611
22: wrap: 1316288537
23: wrap: -346101685
24: wrap: -1038305055
25: wrap: 1180052131
26: wrap: -754810903
27: wrap: 2030534587
28: wrap: 1796636465
29: wrap: 1094942099
30: wrap: -1010140999
31: wrap: 1264544299
32: wrap: -501334399
33: wrap: -1504003197
// Test #2 - no wraparound
...
20: wrap: 1048576
21: wrap: 2097152
22: wrap: 4194304
23: wrap: 8388608
24: wrap: 16777216
25: wrap: 33554432
26: wrap: 67108864
27: wrap: 134217728
28: wrap: 268435456
29: wrap: 536870912
30: wrap: 1073741824
31: wrap: -2147483648
32: wrap: 0
33: wrap: 0
If test #1 were to continue, then the values would keep wrapping. If test #2 were to continue, then the values would stay the same at 0.
The easiest way for me to make sense of this experiment was to know that multiplying by a power of 2 (2, 4, 8, 16, 32..) is the exact same as a bit shift in the binary computer. And, the bits that made up the int were all just getting pushed out of memory in test #2 until there were no more set bits to manipulate. In test #1, more int memory bits are being flipped in order to continue the wraparound.
I would explain this at a lower level, but there are already many great resources for "bit representation of integer".
~ Danial Goodwin ~
ps - This post was mainly for myself and written quickly. If there are any questions about this, then I'd be happy to elaborate.
Ex: If you have an integer at the max positive value and add one, then the integer will wraparound and be set to the most negative value (if using a signed int. An unsigned int will wraparound to 0). And, vise-versa.
Today, I experienced a bug where I wanted to get a (signed) integer overflow, but unfortunately the int value was just going to zero instead of going to the negative numbers. Thankfully, I knew the memory/bit representation of int and was able to figure out what was going on.
Here is some simplified code, with only one small change:
// Test #1 - has wraparound
int wrap = 1;
for (int i = 0; i < 34; i++) {
print(i + ": wrap: " + wrap);
wrap = wrap * 3;
}
// Test #2 - no wraparound
int wrap = 1;
for (int i = 0; i < 34; i++) {
print(i + ": wrap: " + wrap);
wrap = wrap * 2;
}
Here is the relevant output from running the code above:
// Test #1 - has wraparound
...
13: wrap: 1594323
14: wrap: 4782969
15: wrap: 14348907
16: wrap: 43046721
17: wrap: 129140163
18: wrap: 387420489
19: wrap: 1162261467
20: wrap: -808182895
21: wrap: 1870418611
22: wrap: 1316288537
23: wrap: -346101685
24: wrap: -1038305055
25: wrap: 1180052131
26: wrap: -754810903
27: wrap: 2030534587
28: wrap: 1796636465
29: wrap: 1094942099
30: wrap: -1010140999
31: wrap: 1264544299
32: wrap: -501334399
33: wrap: -1504003197
// Test #2 - no wraparound
...
20: wrap: 1048576
21: wrap: 2097152
22: wrap: 4194304
23: wrap: 8388608
24: wrap: 16777216
25: wrap: 33554432
26: wrap: 67108864
27: wrap: 134217728
28: wrap: 268435456
29: wrap: 536870912
30: wrap: 1073741824
31: wrap: -2147483648
32: wrap: 0
33: wrap: 0
If test #1 were to continue, then the values would keep wrapping. If test #2 were to continue, then the values would stay the same at 0.
The easiest way for me to make sense of this experiment was to know that multiplying by a power of 2 (2, 4, 8, 16, 32..) is the exact same as a bit shift in the binary computer. And, the bits that made up the int were all just getting pushed out of memory in test #2 until there were no more set bits to manipulate. In test #1, more int memory bits are being flipped in order to continue the wraparound.
I would explain this at a lower level, but there are already many great resources for "bit representation of integer".
~ Danial Goodwin ~
ps - This post was mainly for myself and written quickly. If there are any questions about this, then I'd be happy to elaborate.
2013-01-25
LegalZoom: Simply Advanced, LLC
Finally, just submitted all the documents and payments to LegalZoom so that Simply Advanced, LLC could be official. I heard a few good things about them and this is the real test for me. LegalZoom says that the filing process could take anywhere from 20-35 days. I will share with the world how the experience goes.
The application process on LegalZoom is relatively straightforward. On the first page, they say it will take about 15 minutes to complete. I'm sure I spent at least 30 minutes reading every question and help available. Be sure to read about the details of LegalZoom LLC creation before beginning the process. There are a few fees that they don't tell you about during the application process.
One interesting experience while filling out all of the forms was getting a phone call by one of the LegalZoom representatives. I didn't have any questions at the time, but I'm sure it can be really useful. And now I have the email and phone number of a specific representative, rather than an overarching number with menus and submenus.
I've read a lot about starting and running businesses already, but there is still a lot of business materials that I have to read before considering myself capable of running this business. It's time to learn fast by throwing myself into it.
~ Simply Advanced ~
The application process on LegalZoom is relatively straightforward. On the first page, they say it will take about 15 minutes to complete. I'm sure I spent at least 30 minutes reading every question and help available. Be sure to read about the details of LegalZoom LLC creation before beginning the process. There are a few fees that they don't tell you about during the application process.
One interesting experience while filling out all of the forms was getting a phone call by one of the LegalZoom representatives. I didn't have any questions at the time, but I'm sure it can be really useful. And now I have the email and phone number of a specific representative, rather than an overarching number with menus and submenus.
I've read a lot about starting and running businesses already, but there is still a lot of business materials that I have to read before considering myself capable of running this business. It's time to learn fast by throwing myself into it.
~ Simply Advanced ~
2012-09-03
Holding My Breath
I just randomly decided to time how long I can hold my breath. I was thinking somewhere in the ballpark of one minute. But, at about 1'35" I looked at my watch and I was still holding on. Then, I just decided to stop right on the two minute mark because I wasn't sure if I was doing something wrong...
I've always wondered how long I could hold my breath, but I never expected it to be this much. My previous max was maybe something like 1'45" when I was a lot smaller and swimming more often (I pretty much don't swim nowadays unfortunately).
Some things that may have contributed to my current two minute record:
~ Simply Advanced ~
I've always wondered how long I could hold my breath, but I never expected it to be this much. My previous max was maybe something like 1'45" when I was a lot smaller and swimming more often (I pretty much don't swim nowadays unfortunately).
Some things that may have contributed to my current two minute record:
- Randomly, I hold my breath as long as I can. No reason that I can think of.
- I slowed my respiratory rate down the minute before timing.
- And something I read about before but never had the opportunity to test.. Take about four really deep quick breaths right before going for the record.
It works.
~ Simply Advanced ~
Subscribe to:
Posts (Atom)