<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 27, 2016, at 8:52 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Wed, Jul 27, 2016 at 10:30 PM, David Owens II via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br class="">
&gt; On Jul 27, 2016, at 7:18 PM, John McCall &lt;<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;<br class="">
&gt;&gt; On Jul 27, 2016, at 6:55 PM, David Owens II via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;&gt;<br class="">
&gt;&gt; Yes, it’s per file. It’s also added in the initial template that Xcode creates with your project. In addition, it’s recommended by many that talk about “how to unit test in Swift.” So, to someone that is not paying scrupulous attention, there is no mechanism to prevent against this today.<br class="">
&gt;<br class="">
&gt; Perhaps we're not doing a good job of messaging this.<br class="">
&gt;<br class="">
&gt; The Xcode template is the way it is because @testable imports are the right default for a *program* written in Swift.&nbsp; A lot of the code in an application or command-line program isn't really suitable for independent, in-process black-box testing, because it isn't really presenting an integrated API.&nbsp; If you break it down into components that can be independently tested, that's awesome, and at that point you can switch the imports in your tests over to non-@testable.&nbsp; But we don't want the test template to create any obstacles to testing, because as you say, people already don't write enough tests.<br class="">
<br class="">
</span>My primary concern is that it’s easy to think you’ve done the right thing and push out a release because all of your testing shows it’s good, only to find you messed up in a way that it’s easy for a tool to validate. Writing new code is probably not going to be the primary source of this, but refactoring a `public` class to an `open` one, where there are already existing tests for that class, probably in a single file and using `@testable`, it’s easy to say, “looks good, tests passed, integrations look good.”<br class=""></blockquote><div class=""><br class=""></div><div class="">If you're refactoring `public` classes into `open` ones, though, you'd be more likely to have forgotten to open a method you intend to make overridable, no? And there's no way to change the rules here to have `@testable` pick that up…</div></div></div></div></div></blockquote><div><br class=""></div><div>Yes, `@testable` does exactly that. It basically treats the imported module as being part of the module it’s being imported into and gives the type all of the same access levels. So I’d be able to override a method that is *not* marked as open with no issues.</div><div><br class=""></div><div>I see nothing in the proposal that restricts a class within the same module from subclassing and overriding `public` methods within the *same* module that it’s defined in.</div><div><br class=""></div><div>So you need to have test cases that have *no* `@testable import ModuleToTest` to ensure the API contracts are being tested well. This is John’s point, that proper public API (e.g. “black box”) test cases would alleviate this issue from happening.</div><div><br class=""></div><div>-David</div></div><br class=""></body></html>