title: How to Unit Test utility class in ios Swift?
body: <p>I am new to Unit Testing. I have learned to create unit test for view controllers, UITableView and URL session. But in projects we usual have Utility class having functions like storing data in User Defaults, checking network, some other handy calculations etc. My question is should we Unit Test these kind of Utility Classes?
  If yes how these unit test can be implemented?
  Update: here's some of the functions in Utility class</p>
  <pre><code> //MARK: Store/Retrive Wathclist symbol from persistent storage
      static func storeToPersistent(List: [String]){
          UserDefaults.standard.setValue(List, forKey: &quot;WatchList&quot;)
      }
      
      static func getFromPersistent() -&gt; [String]{
          if let arr = UserDefaults.standard.value(forKey: &quot;WatchList&quot;) as? [String]{
              return arr
          } else {
              return []
          }
      }
      
      //MARK: Internet availability
      static func isInternetAvailable() -&gt; Bool {
          /// Sample Socket Address
          var zeroAddress = sockaddr_in()
          zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
          zeroAddress.sin_family = sa_family_t(AF_INET)
          
          /// Reachability status
          let defaultRouteReachability = withUnsafePointer(to: &amp;zeroAddress) {
              $0.withMemoryRebound(to: sockaddr.self, capacity: 1) { zeroSockAddress in
                  SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)
              }
          }
          
          /// Flags of Reachability
          var flags = SCNetworkReachabilityFlags()
          if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &amp;flags) {
              return false
          }
          
          /// Check Connectivity Flag
          let isReachable = flags.contains(.reachable)
          /// If needs a Conection
          let needsConnection = flags.contains(.connectionRequired)
          return (isReachable &amp;&amp; !needsConnection)
      }
  </code></pre>