Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needle Usage for Integration testing #462

Open
ShubhangTripathi opened this issue Jul 6, 2023 · 0 comments
Open

Needle Usage for Integration testing #462

ShubhangTripathi opened this issue Jul 6, 2023 · 0 comments

Comments

@ShubhangTripathi
Copy link

Hello Team,
We are looking into re-using Components for our integration testing purposes. We plan on using a separate DI hierarchy for the testing purpose, and wanted to re-use most of our regular components with minor modifications. For example:

class RootComponent: BootstrapComponent {
  var networkComponent: NetworkComponent {
   return NetworkComponent(parent: self)
  }
  .
  .
  .
}
class NetworkComponent: Component<NetworkDependency> {
  var urlSession: URLSession {
     <returns an actual URL session>
  }
 .
 .
 .
}

Now, when we want to create one for testing, we would like to have something like:

class TestNetworkComponent: NetworkComponent {
  override var urlSession: URLSession {
     <returns a mock of URLSession>
  }
}
class TestRootComponent: BootstrapComponent {
  var networkComponent: NetworkComponent {
   return TestNetworkComponent(parent: self)
  }
  .
  .
  .
}

Here, we inherit the NetworkComponent and override urlSession, but the other members are inherited. Now we can use this TestNetworkComponent as part of the testing DI hierarchy.

Currently this approach does not work, since TestNetworkComponent is not picked up by needle's code generator and we run into runtime issues.

Is this something the team might be interested in adding support for? Or any recommendations to do things in a different way?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant