17. What are SmokeTests?
By Brandonrush: https://commons.wikimedia.org/wiki/File:Smoke_Testing,_726_Emma_Ave,_Springdale,_AR.jpg
18. What are SmokeTests?
In computer programming and
software testing, smoke testing
is preliminary testing to reveal
simple failures severe enough to
reject a prospective software
release.
Source: https://en.wikipedia.org/wiki/Smoke_testing
20. What are SmokeTests?
1. … be simple
2. … be fast
3. … test URLs and optional parameters too
4. … cover at least all URLs in google index
5. … be extended by every new URL
6. … never forget a URL
7. … use a (manual) maintained list of URLs
SmokeTests should…
21. What are SmokeTests?
1. Status code
2. Time to first byte
3. If body is provided
4. Correct server
What SmokeTests validate?
22. What are SmokeTests?
SmokeTest
Client
HTTP 1.1/200 OK
<html>
<head>
<title>Foo</title>
<body>
<div id="bar"><span>foobar</span></div>
</body>
</html>
SmokeTests are NOT Acceptance Tests!
24. How do SmokeTests work?
https://2019.phpsrbija.rs
<html><body>…</body></html>
TTFB: 65ms
HTTP 1.1/200 OK
SmokeTest
Client
CI Server
Application
to test
Production Server
25. How do SmokeTests work?
https://2019.phpsrbija.rs/foo
<html><body>…</body></html>
TTFB: 3ms
HTTP 1.1/404 Not Found
SmokeTest
Client
CI Server Production Server
Application
to test
26. class SmokeTest extends TestCase
{
/**
* @dataProvider urlProvider
*/
public function testWebsiteUrl(Url $url)
{
$result = $this->sendGetRequest($url);
$this->assertSame(200, $result->getStatusCode());
$this->assertNotEmpty($result->getBody());
$this->assertLessThanOrEqual(100, $result->getTimeToFirstByteInMilliseconds());
}
public function urlProvider()
{
$urls = [‘http://www.kartenmacherei.de’, …];
$urlCollection = UrlCollection::fromStrings($urls);
return $urlCollection->asDataProviderArray($urlCollection);
}
…
Logic is in here
29. How do SmokeTests work?
SmokeTest
Client
CI Server
Application
to test
Production Server
https://2019.phpsrbija.rs/news
https://2019.phpsrbija.rs/talks
https://2019.phpsrbija.rs
30. How do SmokeTests work?
https://2019.phpsrbija.rs/news
https://2019.phpsrbija.rs/talks
https://2019.phpsrbija.rs
TTFB: 34ms
SmokeTest
Client
CI Server
Application
to test
Production Server
31. How do SmokeTests work?
https://2019.phpsrbija.rs/schedule
https://2019.phpsrbija.rs/talks
https://2019.phpsrbija.rs
SmokeTest
Client
CI Server
Application
to test
Production Server
32. How do SmokeTests work?
TTFB: 65ms
https://2019.phpsrbija.rs/schedule
https://2019.phpsrbija.rs/talks
https://2019.phpsrbija.rs
SmokeTest
Client
CI Server
Application
to test
Production Server
33. How do SmokeTests work?
https://2019.phpsrbija.rs/speakers
https://2019.phpsrbija.rs/schedule
https://2019.phpsrbija.rs/talks
SmokeTest
Client
CI Server
Application
to test
Production Server
34. How do SmokeTests work?
TTFB: 620ms
https://2019.phpsrbija.rs/speakers
https://2019.phpsrbija.rs/schedule
https://2019.phpsrbija.rs/talks
SmokeTest
Client
CI Server
Application
to test
Production Server
38. There is a library for it
DjThossi/smoke-testing-php
39. How do SmokeTests work?
DataProvider
Single Test
Application
HTTP Requests
HTTP Responses
PHPUnit
Calls
Result[ ]
Result
40. class SmokeTest extends TestCase
{
/**
* @dataProvider myDataProvider
*/
public function testExample(Result $result): void
{
...
}
public function myDataProvider(): array
{
…
}
}
41. public function myDataProvider(): array
{
$urls = ['http://www.kartenmacherei.de', …];
$options = new SmokeTestOptions(
UrlCollection::fromStrings($urls),
new RequestTimeout(2),
new FollowRedirects(true),
new Concurrency(3),
new BodyLength(500)
);
return $this->runSmokeTests($options);
}
42. public function myDataProvider(): array
{
$urls = ['http://www.kartenmacherei.de', …];
$options = new SmokeTestOptions(
UrlCollection::fromStrings($urls),
new RequestTimeout(2),
new FollowRedirects(true),
new Concurrency(3),
new BodyLength(500)
);
return $this->runSmokeTests($options);
}
43. public function myDataProvider(): array
{
$urls = ['http://www.kartenmacherei.de', …];
$options = new SmokeTestOptions(
UrlCollection::fromStrings($urls),
new RequestTimeout(2),
new FollowRedirects(true),
new Concurrency(3),
new BodyLength(500)
);
return $this->runSmokeTests($options);
}
44. class SmokeTest extends TestCase
{
use SmokeTestTrait;
public function myDataProvider(): array
{
$urls = ['http://www.kartenmacherei.de', …];
$options = new SmokeTestOptions(
UrlCollection::fromStrings($urls),
new RequestTimeout(2),
new FollowRedirects(true),
new Concurrency(3),
new BodyLength(500)
);
return $this->runSmokeTests($options);
}
…
45. class SmokeTest extends TestCase
{
use SmokeTestTrait;
/**
* @dataProvider myDataProvider
*/
public function testExample(Result $result): void
{
…
}
…
46. class SmokeTest extends TestCase
{
use SmokeTestTrait;
/**
* @dataProvider myDataProvider
*/
public function testExample(Result $result): void
{
$this->assertSuccess($result);
$this->assertTimeToFirstByte(new TimeToFirstByte(100), $result);
$this->assertBodyNotEmpty($result);
$this->assertHeaderExists(
Header::fromPrimitives(‘App-Server', ‘Fury’),
$result
);
}
…
47. class SmokeTest extends TestCase
{
use SmokeTestTrait;
/**
* @dataProvider myDataProvider
*/
public function testExample(Result $result): void
{
$this->assertSuccess($result);
$this->assertTimeToFirstByte(new TimeToFirstByte(100), $result);
$this->assertBodyNotEmpty($result);
$this->assertHeaderExists(
Header::fromPrimitives(‘App-Server', ‘Fury’),
$result
);
}
…
48. class SmokeTest extends TestCase
{
use SmokeTestTrait;
/**
* @dataProvider myDataProvider
*/
public function testExample(Result $result): void
{
$this->assertSuccess($result);
$this->assertTimeToFirstByte(new TimeToFirstByte(100), $result);
$this->assertBodyNotEmpty($result);
$this->assertHeaderExists(Header::fromPrimitives(‘App-Server', ‘Fury’), $result);
}
public function myDataProvider()
{
$urls = ['http://www.kartenmacherei.de', …];
$options = new SmokeTestOptions(
UrlCollection::fromStrings($urls),
new RequestTimeout(2),
new FollowRedirects(true),
new Concurrency(3),
new BodyLength(500)
);
return $this->runSmokeTests($options);
}