Flutter Basics: HTTP Post Requests

Myself and the rest of Team Tiger (from the Flutter dev internship program we’ve recently joined) have just been handed a challenge to work with a simple API, to send HTTP requests and receive responses which a mobile app should understand. I’ve always been fond of reading and understanding web network requests, and knew the challenge would be fun.

If we want to work with HTTP requests, we need to import several dependencies:

The dart packages are built into Flutter, but we also need an external http package, which we have to include in our pubspec.yaml file, like so:

And now we can try sending post requests through our mobile app! Here’s an example code of asynchronously deleting something through an API:

The code is straightforward, sending a .post() method containing the URL of where we want to perform an activity and a  body field which tells us what information we need to send to said URL, all inside an asynchronous Future. We specify that we want to close the HTTP client after the POST request gets completed by sending a client.close command inside the .whenComplete() method.

We can change the app state by running desired commands inside the setState() method. In the example code above, we’re just printing the response received from the POST request. What you want to do about that response is up to you. You can also return the response to someplace in the app if you want.

The if (!mounted) clause is there just to guard us from situations where the user suddenly moves to another part of the application while the POST request is still running. In that case, the request immediately stops and sends a desired return.

Takeaways from Timothy Ferriss’ “The 4-Hour Body”

This year, I decided I was going to get better at exercising. To do that, I thought about reading a few books to give myself an idea on how to go about it. One such book was Timothy Ferriss’ “The 4-Hour Body“, which is a goldmine of content. In it are suggested exercises that gets the job done, walkthroughs, and some science of how things work. But the book is so much more than just a guide on physical exercises. There’s ideas on self-experimentation, adherence, being proactively skeptical, harajuku moments, a slow-carb diet, and more.

Here are some favorite takeaways:

  • Science starts with educated (read: wild-ass) guesses. Then it’s all trial and error. Sometimes you predict correctly from the outset. More often, you make mistakes and stumble across unexpected findings, which lead to new questions. If you want to sit on the sidelines and play full-time skeptic, suspending actions until a scientific consensus is reached, that’s your choice. But don’t use skepticism as a thinly veiled excuse for inaction or remaining in your comfort zone. Be skeptical, but for the right reason: because you’re looking for the most promising option to test in real life. Be proactively skeptical, not defensively skeptical.
  • We break commitments to ourselves with embarrassing regularity. How can someone trying to lose weight binge on an entire pint of ice cream before bed? How can even the most disciplined of executives fail to make 30 minutes of time per week for exercise? How can someone whose marriage depends on quitting smoking pick up a cigarette? Simple: logic fails.
  • Take adherence seriously: will you actually stick with this change until you hit your goal? If not, find another method, even if it’s less effective and less efficient. The decent method that you follow is better than the perfect method you quit.
  • Self-experimentation can be used by non-experts to (a) see if the experts are right and (b) learn something they don’t know. When you study your own problem (e.g. acne), you care more about finding a solution than others are likely to care.
  • If results are fast and measurable, self-discipline isn’t needed.
  • If you want to be more confident or effective, rather than relying on easily-defeated positive thinking and mental gymnastics, learn to run faster, lift more than your peers, or lose those last ten pounds. It’s measurable, it’s clear, you can’t lie to yourself. It therefore works. The Cartesian separation of mind and body is false. They’re reciprocal. Start with the precision of changing physical reality and a domino effect will often take care of the internal.
  • Job not going well? Company having issues? Some idiot making life difficult? If you add ten laps to your swimming, or if you cut five seconds off your best mile time, it can still be a great week. Controlling your body puts you in life’s driver’s seat.
  • Recreation is for fun. Exercise is for producing changes. Don’t confuse the two.
  • People suck at following advice. Even the most effective people in the world are terrible at it. There are two reasons:
    • Most people have an insufficient reason for action. The pain isn’t painful enough. It’s a nice-to-have, not a must-have.
    • There are no reminders. No consistent tracking = no awareness = no behavioral change. Consistent tracking, even if you have no knowledge of fat-loss or exercise, will often beat advice from world-class trainers.
  • For a long time, I’ve known that the key to getting started down the path of being remarkable in anything is to simply act with the intention of being remarkable. If I want a better-than-average career, I can’t simply go with the flow and get it. Most people do just that: they wish for an outcome but make no intention-driven actions toward that outcome. If they would just do something most people would find that they get some version of the outcome they’re looking for. That’s been my secret. Stop wishing and start doing.

Web Accessibility Visualization Tool: tota11y

Testing web sites and apps come in many forms. Testers try their best to test everything, but obviously there’s only so much they can do within a schedule. Some forms of testing are more prioritized than others, and that’s not inherently bad; for a solo tester on a team, one usually tests in a way that covers more bases at the beginning.

Web accessibility testing is one of those forms of testing that often takes a backseat, sometimes even forgotten. Web accessibility helps people with disabilities get better surfing experience. Although websites are typically not built with such functionality in mind, it matters.

And tota11y is a tool from Khan Academy we can leverage for testing accessibility. It is available as an easy-to-use bookmarklet. For whatever page we want to test, we just need to go there and click the bookmarklet, after which the tool will appear on the bottom left corner of the page. Clicking the tool reveals options and using each helps us spot common accessibility violations.

Here are some screenshots of using it on a page I test at work, checking headings, contrast, and link text:

Spotted: Nonconsecutive heading level use

Multiple insufficient contrast ratio violations

And unclear link texts

Looks like there’s room for improvement, although these violations are not necessarily errors.

Flutter Dev Intern: One Month In

A month ago, I got accepted into a no-pay internship program volunteering as a Flutter programmer. It’s an interesting learning opportunity; I’m working with four other programmers from around the globe who personally don’t know each other, building native mobile apps on our free time. The program runs for six months, so I suppose I’ll be writing code with these guys until around April next year.

Team chat over at Discord 🙂

Even though there’s no pay and I spend time to help the team finish given app challenges, what I get in return is an insider experience working with a remote team as a programmer myself, instead of being a tester. That means I need to pitch in on the actual application code, and pitch in with a respectable level of quality. Although I already work with programmers on my day job, the communication dynamics is a bit different from what I encounter on a daily basis. It’s a good change of pace, and I’m somehow broadening my horizons a little.

Most of this past month’s challenge erred on the side of communication: talking to each other over at Discord, familiarizing ourselves with other people’s style of writing code, and gauging our roles within the team. It’s been fun so far. 🙂

Five People and Their Thoughts (Part 8)

Sharing a new batch of engaging videos from people I follow, which I hope you’ll come to like as I do:

  • Workarounds (by Alan Richardson, about workarounds, how you can use them in testing, custom-using tools, moving boilerplate to the appendix, bypassing processes that gets in the way, understanding risks and value, technical skills, and taking control of your career)
  • 100% Coverage is Too High for Apps! (by Kent Dodds, on code coverage, what it tells you, as well as what it does not tell you)
  • Open Water Swimming (by Timothy Ferriss, about fears, habits, total immersion swimming, Terry Laughlin, compressing months of conventional training into just a few days, and the power of micro-successes)
  • How To Stop Hating Your Tests (by Justin Searls, representing Test Double, on doing only three things for tests, avoiding conditionals, consistency, apparent test purpose, redundant test coverage, optimizing feedback loops, false negatives, and building better workflows)
  • Meaning of Life (by Derek Sivers, about a classic unsolvable problem, using time wisely, making good choices, making memories, the growth mindset, inherent meaning, and a blank slate)

Set Cucumber to Retry Tests after a Failure

This is probably old news, but I only recently found out that there is a way for Cucumber tests running in Ruby to automatically retry when they fail.

Here’s a sample failing test:

Apparently we can just add a --retry command to set the test to retry if it fails. And we can set how many times we want the test to retry. If we retry the failing test above to retry two times, with a --retry 2 command, we’ll get the following output:

It did retry the test twice, after the initial failure. Neat! 🙂

But what happens if we run the test, with the same retry command, and the test passes? Does the test run three times? Let’s see:

Good, the retry command gets ignored when the test passes.

Notes from Paulo Coelho’s “The Alchemist”

Paulo Coelho’s “The Alchemist” has been around a while but I’ve never read it before until now. It’s a short book that tells the adventure of a young Santiago in pursuit of his treasure under the pyramids of Egypt, and tries to inspire readers to do the same, to go in pursuit of their own dreams. It’s a story that has remained popular in bookstores all these years and now I understand why. Personally, however, I’ve found it to be a bit underwhelming, perhaps because the writing wasn’t to my taste.

Nevertheless, here are some interesting lines from the book:

  • That was what made traveling appeal to him – he always made new friends, and he didn’t need to spend all of his time with them. When someone sees the same people every day, as had happened with him at the seminary, they wind up becoming a part of that person’s life. And then they want the person to change. If someone isn’t what others want them to be, the others become angry. Everyone seems to have a clear idea of how other people should lead their lives, but none about his or her own.
  • “People learn, early in their lives, what is their reason for being,” said the old man, with a certain bitterness. “Maybe that’s why they give up on it so early, too.”
  • The sheep had taught him something even more important; that there was a language in the world that everyone understood, a language the boy had used throughout the time that he was trying to improve things at that shop. It was the language of enthusiasm, of things accomplished with love and purpose, and as part of a search for something believed in and desired.
  • I know why I want to get back to my flock, he thought. I understand sheep; they’re no longer a problem, and they can be good friends. On the other hand, I don’t know if the desert can be a friend, and it’s in the desert that I have to search for my treasure.
  • He still had some doubts about the decision he had made. But he was able to understand one thing; making a decision was only the beginning of things.
  • “I’m alive,” he said to the boy, as they ate a bunch of dates one night, with no fires and no moon. “When I’m eating, that’s all I think about. If I’m on the march, I just concentrate on marching. If I have to fight, it will be just as good a day to die as any other.”
  • Most people see the world as a threatening place, and, because they do, the world turns out, indeed, to be a threatening place.
  • “Everyone has his or her own way of learning things,” he said to himself. “His way isn’t the same way as mine, nor mine as his. But we’re both in search of our Personal Legends, and I respect him for that.”

 

 

Cypress and Mochawesome

A week ago I was working on a quick automation project which asks for an HTML report of the test results to go along with the scripts. It was a straightforward request, but it was something that I don’t usually generate. Personally I find test results being displayed in a terminal to be enough, but for the said task I needed a report generator. I had already decided to use Cypress for the job so I needed something that plays well with it. In their docs I found a custom reporter called Mochawesome.

To install it, I updated the package.json file inside the project directory to include the reporter:

The Cypress documentation on Reporters also said that for Mochawesome to properly work I should also install mocha as a dev dependency, so that’s what I did.

And then run npm install on the terminal to actually install the reporter.

Before running tests, there’s a tiny change we need to write on the cypress.json file inside the project directory, which tells Cypress which reporter do we want to use for generating test reports.

And we’re all set after all that. 🙂

Run Cypress tests by running cypress run --reporter mochawesomeOr if you specified a script in the package.json file the same way I did in the first photo above, just run npm test.

After running tests, we’re going to find out that a mochawesome-report directory has been added to our project directory which houses both HTML and JSON reports of the tests.

A sample HTML test report looks something like this:

Looks nice and simple and ready for archiving.

Takeaways from Derek Sivers’s “Anything You Want”

Derek Sivers, in his book titled “Anything You Want“, shares tales and lessons he’s learned when he started, built, and sold CD Baby, a global music distribution platform, for $22M (which will return to musicians after he dies). He’s an entrepreneur, but a divergent kind of entrepreneur from the ones I’m accustomed to, and I’ve grown fond of his philosophies in both business and in life. Perhaps it’s because of Seth Godin‘s influence, perhaps it’s because he’s a very slow thinker, perhaps it’s because the things he says just sounds about right.

Some favorite lines from the book:

  • Most people don’t know why they’re doing what they’re doing. They imitate others, go with the flow, and follow paths without making their own. They spend decades in pursuit of something that someone convinced them they should want, without realizing that it won’t make them happy. Don’t be on your deathbed someday, having squandered your one chance at life, full of regret because you pursued little distractions instead of big dreams. You need to know your personal philosophy of what makes you happy and what’s worth doing.
  • The key point is that I wasn’t trying to make a big business. I was just daydreaming about how one little thing would look in a perfect world. When you make a business, you get to make a little universe where you control all the laws. This is your utopia. When you make it a dream come true for yourself, it’ll be a dream come true for someone else, too.
  • Success comes from persistently improving and inventing, not from persistently doing what’s not working. We all have lots of ideas, creations, and projects. When you present one to the world and it’s not a hit, don’t keep pushing it as is. Instead, get back to improving and inventing. Present each new idea or improvement to the world. If multiple people are saying, “Wow! Yes! I need this! I’d be happy to pay you to do this!” then you should probably do it. But if the response is anything less, don’t pursue it.
  • If you’re not saying “Hell yeah!” about something, say no. When deciding whether to do something, if you feel anything less than “Wow! That would be amazing! Absolutely! Hell yeah!” then say no. When you say no to most things, you leave room in your life to throw yourself completely into that rare thing that makes you say, “Hell yeah!” We’re all busy. We’ve all taken on too much. Saying yes to less is the way out.
  • Never forget that absolutely everything you do is for your customers. Make every decision – even decisions about whether to expand the business, raise money, or promote someone – according to what’s best for your customers. If you’re ever unsure what to prioritize, just ask your customers the open-ended question, “How can I best help you now?” Then focus on  satisfying those requests. None of your customers will ask you to turn your attention to expanding. They want you to keep your attention focused on them. It’s counter-intuitive, but the way to grow your business is to focus entirely on your existing customers. Just thrill them, and they’ll tell everyone.
  • Watch out when anyone (including you) says he wants to do something big, but can’t until he raises money. It usually means the person is more in love with the idea of being big-big-big than with actually doing something useful. For an idea to get big-big-big, it has to be useful. And being useful doesn’t need funding. If you want to be useful, you can always start now, with only 1 percent of what you have in your grand vision. It’ll be a humble prototype version of your grand vision, but you’ll be in the game. You’ll be ahead of the rest, because you actually started, while others are waiting for the finish line to magically appear at the starting line.
  • Never forget why you’re really doing what you’re doing. Are you helping people? Are they happy? Are you happy? Are you profitable? Isn’t that enough?
  • We all grade ourselves by different measures:
    • For some people, it’s as simple as how much money they make. When their net worth is going up, they know they’re doing well.
    • For others, it’s how much money they give.
    • For some, it’s how many people’s lives they can influence for the better.
    • For others, it’s how deeply they can influence just a few people’s lives.
    • For me, it’s how many useful things I create, whether songs, companies, articles, websites, or anything else. If I create something that is not useful to others, it doesn’t count. But I’m also not interested in doing something useful unless it needs my creative input.
  • When you want to learn how to do something yourself, most people won’t understand. They’ll assume the only reason we do anything is to get it done, and doing it yourself is not the most efficient way. But that’s forgetting about the joy of learning and doing. Yes, it may take longer. Yes, it may be inefficient. Yes, it may even cost you millions of dollars in lost opportunities because your business is growing slower because you’re insisting on doing something yourself. But the whole point of doing anything is because it makes you happy! That’s it! You might get bigger faster and make millions if you outsource everything to the experts. But what’s the point of getting bigger and making millions? To be happy, right? In the end, it’s about what you want to be, not what you want to have. To have something (a finished recording, a business, or millions of dollars) is the means, not the end. To be something (a good singer, a skilled entrepreneur, or just plain happy) is the real point. When you sign up to run a marathon, you don’t want a taxi to take you to the finish line.

Interview Questions Template

How does your day-to-day work look like?
What do you know about software testing? How about being a scrum master?

What is your most favorite part of the work? Your least favorite?
Have you taken part in a project that you’re really proud of?

What made you decide to apply for this position?
Why not apply for a programmer job?

What three skills do you think matters most to a tester? To a scrum master?
How do you rate yourself in those skills?
What skill would you say you’ve actively pursued recently?

Are you familiar with the following?

  • Risk
  • Exploratory testing
  • Automation
  • Test-driven development
  • Behavior-driven development
  • Agile
  • Pairing
  • Retrospective

Do you have hobbies that are important enough to waste time on?
What is one of your favorite movies? A favorite book? A favorite TV series?

Do you have specific goals in mind that you want to achieve when you get this role?
In what ways do you think we can help you achieve those goals?

Do you have questions for me or for your employer?

 

(Because I’ve been scheduled to interview a number of applicants in the coming week and I often forget to ask some of the important questions when I go at it head-on, I thought I needed some sort of template I can always grab and bring)