Pg_tmp – Run tests on an isolated, temporary PostgreSQL database
&gt; There&#x27;s a place for e2e tests that run the actual services, and a place for tests that use mock servers. As a full stack developer, I know for a fact that spinning up a service, even if it&#x27;s dockerized, is more often than not a hassle. Maybe because of configuration hell, maybe because setting up the database (with the migrations, fixture data, etc.) is never a straightforward job even if it&#x27;s &quot;automated&quot;.<p>Configuration hell happens in the cloud as well, and again I noted earlier -- it should be <i>easy</i> for your application to automatically apply and make sure a given database is migrated. Applications shouldn&#x27;t start if they&#x27;re not running on the version of database they expect. Maybe producing fixture data is hard but this is stuff you <i>would have had to do with a mock, anyway</i>. Good mocks also need fixture data because they need to act on that data <i>just like the thing they&#x27;re mocking would</i>.<p>As a side note this is literally what tooling&#x2F;infrastructure engineers get paid to do. They build good systems for application developers so that it will feel like magic. It will be easier for everyone, forever, and you&#x27;re going to reap the rewards in meaningful, impactful tests that are closer to your production infrastructure. People are doing things these days like &quot;testing in production&quot; because mocks just don&#x27;t match production enough.<p>If this is like.. what you should do with 2 engineers at the very beginning of a startup, then sure, write mocks to your heart&#x27;s content. Or even better, don&#x27;t mock anything just write the basic E2E tests (against test cloud resources or your production cloud resources), and get to shipping even faster. If resources are that tight, no one has time to sit around writing mocks in a code-base with a high churn rate right?<p>&gt;  And if the architecture requires service A to talk to service B, which in turn needs to talk to service C, you end up having to spin up way too much infrastructure (each with their own configuration and database setup hells) for just a simple test. It&#x27;s not worth it, and often it&#x27;s not feasible since you may not even have enough memory in your computer.<p>People are running around with $3000 Macbooks with very fast cores and lots of memory, but running their cloud instances with ASGs of t2.micros&#x2F;smalls&#x2F;larges&#x2F;xlarges initially. Half the time all you need for most apps is a database (postgres), cache (redis), message queue (redis), and S3 (minio), and something to send emails. You can run local versions of these requirements on &lt;4 hyper threads (let&#x27;s say 2&#x2F;4 cores). You&#x27;re not going to be able to test BigQuery or DynamoDB (actually, you can run ScyllaDB but that&#x27;s besides the point) or some cloud-specific stuff, but most apps just don&#x27;t need that stuff. It&#x27;s not that hard to run all 5 of these services on a modern dev machine, nevermind if companies spent <i>half</i> the price of the laptop and got you a desktop machine (like the &quot;thin client&quot; business machines out there these days[0]).<p>But again, all I can hear is that the <i>experience</i> is lacking -- you&#x27;ve just never seen it done simply, doesn&#x27;t mean it can&#x27;t be done or it isn&#x27;t a good idea -- you&#x27;ve just never run into a place with the right resources&#x2F;time to build proper developer tooling.<p>I&#x27;d argue it is worth it because you&#x27;re going to build a mock that approximates those services to test them, are you not? Or are you just going to mock that the request came back correctly? I already mentioned that if you want to just <i>not spin the thing up at all</i>, then yeah write a mock for the function call or whatever, but if you&#x27;re going to write a mock for that thing, you&#x27;re basically writing technical debt that will be wrong&#x2F;subtly broken as soon as the underlying thing changes. Why do that when you can just... use the actual thing?<p>&gt; For frontend developers or data scientists who couldn&#x27;t care less about the backend, going through this hassle is frustrating and there&#x27;s no reason why they should go through it.<p>Sure but this is the same point as before -- it&#x27;s hard only when you haven&#x27;t dedicated any engineering time or the right engineers to it. If it&#x27;s crucial to you all moving faster, then take the time, build the shared machinery, and it will pay dividends. Maintaining mocks is not free, and the costs are externalized&#x2F;hidden -- mocks do not maintain parity with the actual implementation, they are a reflection of how you <i>think</i> the actual implementation works.<p>As a side note, if you want to accelerate frontend developers or data scientists there are many other good options -- they can develop against an API instance that&#x27;s in the cloud completely (if you have preview apps for Heroku, or a similar setup elsewhere for example) -- data scientists could use hosted notebooks with access to the appropriate data lakes. There are lots of other things you can do there for a fully streamlined experience. I&#x27;m going to assume that a fully streamlined experience wasn&#x27;t the goal here, but rather easy deployment of this software on their machines -- again, this is a matter of building a good experience. If it&#x27;s hard, make it easy -- write good software and it will look like magic.<p>&gt; Mocks are also a fundamental part of building integrations, since they allow both backend and frontend teams to work in parallel against a specification&#x2F;contract.<p>Mocks are not a fundamental part of building integrations -- the actual backing service is the only fundamental part. This is why people usually just... don&#x27;t worry about writing tests, or don&#x27;t mock when they first start out. Writing and maintaining good mocks that mock what you want and reflect the functionality well is non trivial.<p>Specifying a contract for the software you&#x27;re producing is a good practice, but it is not tied to mocking, it is to afford you flexibility in writing <i>integrations</i> (instances of the interface). You have chosen to write an integration that doesn&#x27;t run <i>anywhere else except in tests</i>. Writing a Queue&lt;LocalMemory&gt; is drastically less useful than writing a Queue&lt;Elasticache&gt; and Queue&lt;Redis&gt; and Queue&lt;Kinesis&gt;, though they are all implementations, because Queue&lt;LocalMemory&gt; is <i>never used anywhere else</i>. Bugs an under-engineering&#x2F;discrepancies in Queue&lt;LocalMemory&gt; will never be seen in production and are a waste to work on, when you can spin up Redis and use Queue&lt;Redis&gt; locally. Queue&lt;Redis&gt; might actually see use in real life, and we know that Queue&lt;Elasticache&gt; and Queue&lt;Redis&gt; are actually kind of the same thing (definitely more-so than Queue&lt;LocalMemory&gt;).<p>&gt; That said, for the real integration test, you do need to run the real services and have them talking to each other. If you can do that in your own machine, great. But often the only feasible way to do this is in the cloud.<p>??? This isn&#x27;t true really. You can absolutely run software on your own machine and fully integration test a system. In fact, for the amount of time that your app&#x27;s database (which is normally the limiting factor size wise) is less than 100GB, you can run most complete apps (imagine a simple one like Laravel&#x2F;Rails&#x2F;Django) on your own machine.<p>If your app can run on &lt;10 t2 instances (let&#x27;s assume 3 of those are RDS), and doesn&#x27;t use more than 500GB of data in total (again, harddrives are bigger than this these days).<p>Look, we don&#x27;t have to agree, diversity of opinion is great -- but none of these arguments are doing it for me. They all just amount to &quot;it&#x27;s hard&quot; with the assumption being that mocks are free. Mocks are not free, and while they may have their place, I would rather just do the work of making it easy for me to spin up the infrastructure where possible. You don&#x27;t have to be an expert -- hire someone else who is to make sure your developers are productive. If it&#x27;s &lt;5 devs then OK, maybe no one has that time or expertise, doesn&#x27;t mean it&#x27;s not a good idea.<p>[0]: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=GTl8fiKEr8g" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=GTl8fiKEr8g</a>