Categories
Software development

Test Driven Development and Unit Test

Reading Time: 2 minutes

(Update 02-19-2021)

spring.io Testing the Web Layer

Mockito Example with Best Practices

JUnit and Mockito : Best Practices, Do’s and Don’ts

(Original) Test Driven Development (TDD) is getting popular these days. I had opportunity to being exposed it recently. I am not new to unit test. In the software company I worked for 8 years, we have regression test suites that runs automatically (at least daily), and we update the test suites as we find edge cases from customer bug reports, or in our development. That was about 8 years ago. Since the switch into Java land (2010), I started using JUnit and create/run the unit tests. One thing I was exposed to recently is Mocking in unit test, and TDD. Both takes a little time, and I am not fully bought into TDD yet. But I did learned something interesting on both topics lately, and like to share.

1) TDD
One of my coworker is very experienced and in-grained in this, as we are doing pair programming, I learned this a bit. An interesting back and forth as I was making changes to a method.

Coworker: “Do you have a test case?”
Me: test case for what?
Coworker: for the change?
Me: do we need this? …

But eventually we wrote the case, magically the web app also worked as soon as we passed the unit test. But overall I still have some reservation to do this, as I am not good at mocking e.g. Mockito, or writing test, and I think there is some cases pair programming can get the code right without go heavy in unit test.

Some links for mockito and spring test

Stubbing and Mocking with Mockito and JUnit


https://www.vogella.com/tutorials/Mockito/article.html
https://stackoverflow.com/questions/39486521/how-do-i-mock-a-rest-template-exchange
https://www.baeldung.com/spring-mock-rest-template
https://stackoverflow.com/questions/11969609/junit-mockito-when-thenreturn-throws-nullpointerexception/18060451
https://javacodehouse.com/blog/mockito-tutorial/

2) Unit test (auto test suites)
I heard from my coworker recently that test suites should not use the implementation data source (database). I thought the main reason is the heavy weight/use from database resources point of view. But there is more, today I found if auto test consistently changes things on dev database, it’s really hard to find out the root cause, and cause confusion. Initially we thought the problem was caused by batch job, or the web app, spent a lot time trying to figure out, both are not the cause. And luckily, at the end we were able to find out the real cause.

Categories
iPhone app

How to make iPhone app iPhone 5 5s compatible

Reading Time: 2 minutes

(Update 03-05-2019, almost 5 years since original post) I did something similar for iPhone X, XR, XS screen size. Basically I stretched the Default-568h@2x.png to Default-375w-812h@3x.png and added that in the “launch image”. I also noticed the some of the nib files have the wrong constraints for label, textfield and button. I made some simple changes so that the top and bottom portions stick. Last but not least, the constraints and the size of google admob banner ads needed similar work: I did the needful and checked those changes worked both for iPhone SE and iPhone X.

I don’t have iPhone X (XR or XS). My first impression they are much longer than the SE I have.

(Original 04-13-2014) I found some iPhone apps are still not updated to take advantage the iPhone 5 screen size (4 inch vs. iPhone 4/4s 3.5 inch). I think in many cases the owner of the apps may not have time or the developers don’t know how to stretch the screen. This is a quite common problem. The solution is also fairly straightforward. We only need the stretched version of the screenshot, and name it as Default-568h@2x.png (exactly like this). But to get this all started, you might want to use this blank png file, something like this:

Default-568h@2x

Add this file to the Xcode project, and run the simulator. Screen capture the first screen and edit it to make sure it’s 640×1136, and name it as the file name above. This way the app will both have a good launch screen and stretched screen for iPhone 5/5s

(Update 04-20-14) I found something more interesting. When I tried to add auto layout for the nib (xib) file created in Xcode 3.x, it basically give me a blanket (black) screen. So basically we can not reuse those old nibs for auto layout.

Categories
Software development

If it’s not broken, don’t fix it?

Reading Time: < 1 minute

This is the common saying I heard a lot when I started worked for a software company on development. I can list some of the pros and cons of fix it.

Pros
Architecture chaos: if not fixing it, basically as the software ages, per the “broken windows” theory, people would just throw in changes to get things done, without carefully thinking about the architecture, dependencies. And this leads to the related problem below.

Code hard to maintain: it will become harder and harder to fix bugs, or add new features with the code in a messy state.

Cons
Introduce new bugs by accident. Or the fix making the software worse. While it’s unlikely, it’s still possible. Not carefully planned fix could introduce bugs, and make the software worse. I have done my share of that too 🙁

Refactor
If we were to work on the clean up, refactor the code, as a minimum we should have the regression test suites. Or in ideal world, we would have automated unit tests, which could help both speed up development, and give another level of confidence for the code change.

Categories
iPhone app

iPad number input only

Reading Time: < 1 minute

There was not an easy way to show the number only keypad on iPad. I used to create a custom number input pad like below.

iPad_number_input

I loosely followed raywenderlich.com custom input tutorial. Email me at minjie Dot xu At gmail Dot com if you need the source code. And please ask nicely.

Categories
iPhone app

Who is going to attempt the last shot?

Reading Time: < 1 minute

I used to watch NBA game quite a bit. I noticed in many teams, there are usually a go-to-guy who attempts the last shot, in close game. This is especially true in important games, such as playoff or elimination games. We all know Kobe Bryan and Lebron James are among those. Is there such a role in software development? Is this role becoming less obvious with the pair programming? When I reflect about all the places I worked, I think the answer is yes for the first question. Actually I played that role from time to time.

And again use that basket ball analogy, I think in a truly agile team everyone can be the go-to-guy. Because in that case, basically the opposing team cannot easily defend, which is ideal for the team. On the other hand, the opposing team just needs to figure out how to defend Lebron James, and they will be more likely be successful. At the same time, Mr. James will get frustrated too as teammate cannot step up, and the loss of games.

This is a bit fitting as we are at march madness, the traditional NCAA basketball playoff game season.

Categories
iPhone app Software development

Why unit test?

Reading Time: 2 minutes

For the pretty reports?
About a year ago, I worked for a client for an iOS project. The developer I worked with is very enthusiastic about unit testing, test driven development. I recall he used some tool (lcov, stands for line coverage), and set up the build script such that the unit test and lcov runs frequently. I was also shown the pretty chart created by lcov. All is good. except one day, I found a utility function I wrote was broken in the iPad simulator. Turns out the developer modified the code and added test for that function (a good thing), but at the same time forgot to run the real thing to check it.

Real motivation for unit testing
I think the unit test as another perspective to verify the code works as desired, this is from my own experience. I recall we have regression test suites in the software company I first worked professionally, that was more than 10 years ago! I started with waterfall, slowly transitioned into agile, test driven development. When we found new test cases (from problem report, etc.), we added those to our regression test suites as we see fit. We ran those unit testing suites before checking in code. This does not means the product we are developing is prefect, but it does give me more confidence as we add features or do bug fixes. This is also true in the many JUnit tests I saw/added in many places I worked since then.

More recently, as I saw the “mock” concept in JUnit, while I am not expert on “mocking”. Conceptually I liked this idea, as we don’t want to repeat the same thing in the production code, we add one more perspective. I also recall the famous investor Charlie Munger (Vice chair of Berkshire Hathaway) once said, he used at least two models to value a company/investment. Check and balance.

(Update) Came across this article on the disadvantages of pair programming. Also, saw this launchCodeSTL a while ago.

Categories
iPhone app

iPhone 5s and iPad mini without data plan

Reading Time: 2 minutes

Recently I cancelled iPad mini $30 per month 3gb data plan from AT&T, note I also have not have phone data plan since the beginning of April of last year, at which time I returned the employer iPhone 4s when I changed job. Now I am without the data plan on 3G, I am formally without the always on data. Some of the work around I have used to get around:

1) Wifi, at work place I usually get free wifi, and I asked the Wifi password at the places I will be for a while, my daughter’s pre-school, her gym class, JCC, the Chinese restaurant I go often, my friend’s house, etc. Most places have free wifi now. The only thing is just ask: the office manager, my friend. Usually they don’t laugh at me 🙂

2) Not all wifi are equal, besides speed, and coverage and reliability is the most visible. Personally, I like the JCC wifi the best, because they are reliable. At one time, I had Nexus 4 phone, it takes a bit work to get connected (Setting, turn Wifi off and back on).

3) GPS. I found out this lately, even without data plan, I can use GPS on my iPad mini, the only thing is before I start, I need the Wifi to set up the destination and the route. After that the navigation is just the same as the dedicated GPS. A small inconvenience. And one reason I still kept my TomTom GPS.

4) Apps’ working without Wifi. I found the iOS support for apps without Wifi varies greatly. I liked the Facebook “Internet connection required” status bar. And I tried to implement something similar in my app when the connection is required.

(Update 03-07-14) Found a solution to a puzzled problem for iPhone 5s on T-mobile pre-paid plan (no data plan). There is no visual voice mail, which is fine. The annoying part is once there is a voice mail, the red dot on the phone icon won’t go away easily. I found how to fix it, basically I turned off cellular data, I turned it on, then off, the red dot will be gone. A small tip.

Categories
Software development Web

Spring MVC, Maven

Reading Time: 2 minutes

I’m back to Java world again, after about 2 years stint on Objective-C and iOS development. I’m not new to Java land, as I have done Java work between 2010 and 2011, for 2 years.

My personal learning experience:
JSF => Spring MVC (jspx is still very similar): I have done JSF, which is a component based Java web framework, we know Spring MVC is different: it’s based on REST, GET, POST, and mapping etc. Luckily I have done RESTful web services in my past work, and used those services from iOS side. Another new thing at client side is javascript, and jQuery, I recall I used Richfaces (extension of JSF) for the AJAX, they are not javascript though.

IBM web sphere/Rational application developer RAD, CVS => Spring STS, SVN, note both RAD/STS are based on Eclipse: for the application server, and development IDE, the transition is easier such they are very similar.

Ant (build.xml) => Maven (pom.xml): this is a big change, actually. Maven has some learning curve, also with the Nexus repository. My only past experience using Maven: use Netbeans to open the project (pom.xml file). I found the following two tutorials helpful.

Tutorial on Maven:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

http://maven.apache.org/guides/getting-started/

Spring MVC: using the Get Started Guide from the dashboard, or the link here.

Obviously, learn as much as possible from the work itself, from coworkers etc. The good thing is my current work place is one of the most collaborative places I’ve ever worked. This makes my life a bit easier 🙂

Repository, Nexus (Sonatype), JFrog Artifactory

JFrog intro: quick youtube video

Comparison between Nexus and JFrog

Sonatype Nexus

Josh Long A Bootiful Podcast : Hi, Spring fans! In this installment Josh Long (@starbuxman) talks about ten years on the Spring team, reactive support, and RSocket support in Spring Integration, his upcoming appearances at SpringOne and his upcoming YOW! workshop on Cloud Native Java, and then talks to JFrog’s Baruch Sadogursky (@jbaruch) about continuous delivery, DevOps, Java artifact management Artifactory, and more.

General questions about JFrog artifactory

Categories
iPhone app

Status of iOS app development II : app store

Reading Time: < 1 minuteThe golden era is over. Some readers/developers will argue it was over a while ago. I know I know. But this problem was confirmed as I read this article on BusinessInsider: it takes 107 swipes to get to the hottest app in app store.

Don’t get me wrong, Apple is still evolving and innovating on this space, with the new iPhone 5s, motion sensor (FitBit app), iBeacon (for retailers), the only thing is the momentum is definitely slowing. All these changes even Siri is not that impressive in my opinion. I do like Facetime, though, esp. I noticed an article talking about Facetime audio which essentially allow one to call other phone over Wifi fore free. Btw, I noticed the article over Zite.

For me personally, I have created 3 apps, and one (myNestEgg) of the 3 still have decent downloads. The problem there is two folds: 1) I did not spend enough time to work on some features to make the user happy; 2) Not many paying customers. I think I will still put some effort on it in the future, but I won’t put a lot hope there. Need to find something more interesting or scalable. It’s too hard to stand out from a million apps. Or even out of 50 and 100 apps in the category.

Competition
Another sign the iOS app developers has to expand their horizon, noticed the No. 1 iOS tutorial website (ebook producer) is doing the Android tutorial? Actually it’s not the first Android tutorial at RayWenderlich.com, I noticed this very first one here. So technically the new one is second series, but it actually helps confirming the popularity of Android platform.

Categories
iPhone app

Status of iOS app I : custom development

Reading Time: < 1 minuteIt has been almost 6 years since iOS SDK first came out (early 2008, source: wikipedia), and the industry is entering a consolidation stage. From my own experience, last year, iOS developers are widely sought after for enterprise app development, and among digital/marketing agencies. But it has a few caveats:

1) Many new developers, some with web development background, have gained experience on app store, and started working for consulting agencies. This trend drives down the hourly rate for iOS developers;

2) From development point of view, some customers realized it’s too costly to develop and maintain native app, and in some cases native apps are not needed. On the other hand, javascript/html5 apps gained some more momentum with the introduction of new frameworks such as AngularJS.

3) The consolidation of iOS/android/mobile custom development firms. Latest example: MartianCraft: its co-founder Jeff Larmache is one of the first iPhone author/developer (his blog here).

In the next series, I will talk about the app store. Got this idea from my own experience and this BI article.