Comments (4)
Hello!
I thought I remember reading that SimpleTest can do Integration tests and not only Unit tests..
- Only assert for the current test case in the current context.
- Do not pass assertion parameters through UnitTestCase context boundaries.
- UnitTests cover the functional behavior of each classes to integrate (standalone).
- IntegrationTests cover the combined behavior of the classes (combinatorical).
The following example unit-tests A, B and C,
then finally we do an integration test for C using A and B.
<?php
require_once __DIR__ . '/../../autorun.php';
require_once __DIR__ . '/../../test_case.php';
class A { function fA() { return 'Hello '; } }
class B { function fB() { return 'World!'; } }
class C { function fC($a, $b) { return $a . $b; } }
class aTest extends UnitTestCase
{
function setUp()
{
$this->A = new A();
}
// unit test for class A - function fA
function testAfA()
{
$this->assertEqual('Hello ', $this->A->fA());
}
}
class bTest extends UnitTestCase
{
function setUp()
{
$this->B = new B();
}
// unit test for class B - function fB
function testBfB()
{
$this->assertEqual('World!', $this->B->fB());
}
}
class cTest extends UnitTestCase
{
function setUp()
{
$this->C = new C();
}
// unit test for class C - function fC
function testCfC()
{
$this->assertEqual('12', $this->C->fC('1', '2'));
$this->assertEqual('NY', $this->C->fC('N', 'Y'));
}
}
class cIntegrationTest extends UnitTestCase
{
function setUp()
{
// we want to test that C works with the following dependencies:
$this->A = new A();
$this->B = new B();
// the subject under test for integration is C
$this->C = new C();
}
function testC_Integrates_With_AB()
{
$this->assertEqual('Hello World!', $this->C->fC($this->A->fA(), $this->B->fB()));
}
}
Why do you get the Fatal error: Call to a member function getDumper()
?
- (
testStart
has no assertion, but instantiatesfooTest
; it should probably be asetUp()
method instead) bazTest extends UnitTestCase
. that's the running test, which has anReporter
object internally.- but
testDo
callsfoo->doFoo()
and leaves the context of the currently running testbazTest
- the
assertTrue()
infooTest->doFoo
doesn't count for thebazTest
, because$this
meansfooTest
, which is anotherUnitTestCase
. that one is currently not being run and has no reporter internally. - in the end it fails, because it can't get the dumper from the reporter
Well, to satisfy you could technically pass the reporter forward - but that creates a real mess.
Don't use this approach! It's just to understand what "context of the running test" means.
<?php
require_once __DIR__ . '/../../autorun.php';
require_once __DIR__ . '/../../test_case.php';
class bazTest extends UnitTestCase
{
function setUp()
{
$this->foo = new fooTest();
// copy the reporter context into the foo object
$this->foo->reporter = $this->reporter;
}
function testDo()
{
$this->foo->doFoo(false);
}
}
class fooTest extends UnitTestCase
{
function doFoo($foo)
{
$this->assertTrue($foo);
}
}
Regards, Jens
from simpletest.
Sorry, didn't mean to be rude. I saw you closed the ticket already and thought I had to reopen the ticket to comment (maybe I was logged out?).
I really appreciate the detailed response, it helps a lot. I've come up with something which works for me now. Rather than have multiple classess extend UnitTestCase - I have separate classes (componentTestA
, .. ) which integrate components, these classes are initialised in the setUp method.
class componentTestA { } class componentTestB { } abstract class TestCase extends UnitTestCase { function setUp() { $this->a = new componentTestA(); $this->b = componentTestB(); } function assertStuffWithA() { $this->assertTrue($a->isTrue()); } function assertStuffWithB() { } } class TestingStuff extends TestCase { function testAB() { $this->assertStuffWithA(); $this->assertStuffWithB(); } }
I'm happy how it's working for me now, my test methods are clear and readable and testCase
has simple interactions with components. A minor gripe is that TestCase
is getting long in the tooth and while testX
methods assert across multiple componentTests
, the individual assertStuffWithX
methods only use a single componentTest
.
On positive side while writing the aTest
classes I'm getting idea's how to refactor the underlying classes.
I did try the workaround you suggested, it worked but I resisted the temptation to leave it in and carry on as I was.
from simpletest.
i appreciate your feedback
from simpletest.
Of course, you can always create an AbstractTestBase class. lgtm
from simpletest.
Related Issues (20)
- assertText and <title> HOT 2
- no referer is given HOT 2
- mock_object is trying to run tell() on non existing object HOT 3
- Unable to click a button. HOT 3
- How can I add Header Referer
- dumper->clipString() is multibyte safe? HOT 1
- i would like commit some code HOT 6
- Mocking interfaces with class definitions in arguments is broken HOT 1
- New Release / Project Status HOT 8
- Documentation translation HOT 5
- Please support cookie/session HOT 1
- Unable to click submit when there is onclick tag HOT 2
- how to click href when there is nowrap
- PHP 7.2: Spurious test errors due to legacy constructors HOT 1
- Syntax error in mocked methods in PHP 7.1+ HOT 3
- TestSuite ends up creating instances of the clases in the hiearchy of a test
- Documentation link is broken or resource unavilable HOT 3
- Failed unit_tests.php HOT 3
- Add support for date and time input fields HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpletest.