<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Farees Hussain</title>
    <description>The latest articles on DEV Community by Farees Hussain (@fareeshussain).</description>
    <link>https://dev.to/fareeshussain</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F454808%2F687fdd5e-4fa3-4995-9f0e-480fabc42c93.png</url>
      <title>DEV Community: Farees Hussain</title>
      <link>https://dev.to/fareeshussain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fareeshussain"/>
    <language>en</language>
    <item>
      <title>Finally Completed Hacktober fest</title>
      <dc:creator>Farees Hussain</dc:creator>
      <pubDate>Wed, 14 Oct 2020 20:15:28 +0000</pubDate>
      <link>https://dev.to/fareeshussain/finally-completed-hacktober-fest-2b2e</link>
      <guid>https://dev.to/fareeshussain/finally-completed-hacktober-fest-2b2e</guid>
      <description>&lt;h2&gt;
  
  
  What I Learned From Hacktoberfest
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lot of things regarding android&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hacktoberfest</category>
    </item>
    <item>
      <title>Basics of TDD in android</title>
      <dc:creator>Farees Hussain</dc:creator>
      <pubDate>Fri, 25 Sep 2020 13:01:17 +0000</pubDate>
      <link>https://dev.to/fareeshussain/basics-of-tdd-2dd9</link>
      <guid>https://dev.to/fareeshussain/basics-of-tdd-2dd9</guid>
      <description>&lt;h3&gt;
  
  
  What are tests and why should you write test cases ?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To make it simple tests are just to check whether the code is working.&lt;/li&gt;
&lt;li&gt;But you can just test it simply then what's the deal with Test Driven Development ?? 🤔🤔&lt;/li&gt;
&lt;li&gt;The issue here is to test a simple code you have to wait to open the App or run the code navigate to the.&lt;/li&gt;
&lt;li&gt;Well, you can do that for once but if you have several test cases where you have to test your code you'll waste a lot of time.&lt;/li&gt;
&lt;li&gt;Here comes TDD(Test Driven Development) in which we test a particular code with given test cases and check all of them once.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understanding Tests in Android
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JUnit&lt;/strong&gt; - JUnit is already included in our Gradle dependencies, using JUnit we can automate the testing process.&lt;/li&gt;
&lt;li&gt;Here we check the functionality of the app use it using different inputs of various test-cases and check them with the final result and the expected result.&lt;/li&gt;
&lt;li&gt;There are Threes kinds in testing -

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Unit Tests&lt;/em&gt;&lt;/strong&gt; - 
These are the fastest tests in our program
Used to test a single function of the app
These make 70% of the testing in our app&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Integration Tests&lt;/em&gt;&lt;/strong&gt; -
To test how two components of our app work together
i.e, to test the interaction between different components in the app.
It is different from the integrated test(which require our app to run in the background)
These make 20% of the testing in our app&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;UI Tests&lt;/em&gt;&lt;/strong&gt; - 
To test all the components of the app runs together
These make 10% of the testing in our app&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Most of the testing part includes Units tests and Integration Tests &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to write good test cases and What is TDD ?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;TDD is a procedure of writing the test case before implementing the functionality&lt;/li&gt;
&lt;li&gt;To write good tests -

&lt;ol&gt;
&lt;li&gt;Write the function of basic implementations or no content.&lt;/li&gt;
&lt;li&gt;Write the test cases which most probably fail the first implementation of the function.&lt;/li&gt;
&lt;li&gt;Now as our function does not pass all the test cases above we implement the logic until all the test cases are passed.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;In TDD we have a single assertion, now what is an assertion. &lt;strong&gt;&lt;em&gt;Assertion&lt;/em&gt;&lt;/strong&gt; is to make sure whether our test case pass or fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Let's start coding !!
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;To get started first I'm gonna start with a simple way to show the basics of unit testing, which can be applied in a real project&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;by default in every project we have three dependencies as below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;You may have noticed 'testImplementation' and 'androidTestImplementation' and also 'androidTest' and 'test' in the root package these are called source sets.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;androidTest&lt;/em&gt;&lt;/strong&gt; Now the Integrated Tests belong to the 'androidTest-Source set' which means they require an android emulator to run the tests. and to add dependencies to this source set we use 'androidTestImplementation' in build.gradle file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;test&lt;/em&gt;&lt;/strong&gt; And the tests that don't require any android components such as context. these tests run on JVM and run fast. and to add dependencies to this source set we use 'testImplementation' in build.gradle file. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;h5&gt;
  
  
  Enough with the Theory now
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There is a CodeForces problem which, we are going to solve using TDD &lt;br&gt;
&lt;a href="http://codeforces.com/contest/344/problem/A" rel="noopener noreferrer"&gt;A. Magnets&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this problem, we have to find out how many groups of magnets can be found if they are arranged in a horizontal manner.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an object 'Magnets'&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fznecpxvsav1he83qdztb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fznecpxvsav1he83qdztb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's create a function that takes an integer and a string as an input and gives no of groups i.e, integer as an output. Now right-click on Magnets and then Generate&amp;gt;Test&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F36np27zj9tiplb6ifhn3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F36np27zj9tiplb6ifhn3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select JUnit4 as the Testing Library and press OK then select test source set as below&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffp0xmuxbpuump636ijjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffp0xmuxbpuump636ijjj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below dependency and after sync, create the code forces test cases as below and run Magnetstest which was created in the above step.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;testImplementation 'com.google.truth:truth:1.0.1' 
// to make assertions easy and readable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F14d2oqudih88lv7ijhfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F14d2oqudih88lv7ijhfn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As our result is 0 always and it doesn't match with the test cases we fail both the test cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now after implementing the correct implementation of the function as below we pass both the test cases.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;object Magnets {
    fun noOfGroupsOfMagnets(n : Int, magnets: Array&amp;lt;String&amp;gt;) : Int{
        var result = 0
        for(i in 0..n-2) if (magnets[i]!=magnets[i+1]) result++
        return ++result
        // ~~ simple solution ~~
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fduq5507v7gis09mf9w8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fduq5507v7gis09mf9w8w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do follow me on DEV.to &lt;/p&gt;
&lt;div class="ltag__user ltag__user__id__454808"&gt;
    &lt;a href="/fareeshussain" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F454808%2F687fdd5e-4fa3-4995-9f0e-480fabc42c93.png" alt="fareeshussain image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/fareeshussain"&gt;Farees Hussain&lt;/a&gt;Follow
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/fareeshussain"&gt;Android Developer &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;For more information on TDD, checkout&lt;br&gt;
 &lt;a href="https://www.youtube.com/playlist?list=PLQkwcJG4YTCSYJ13G4kVIJ10X5zisB2Lq" rel="noopener noreferrer"&gt;Testing-on-Android/Philipp Lackner&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
