tdd

How can I reference external data providers in phpunit?

左心房为你撑大大i 提交于 2019-12-22 10:37:01
问题 I am trying to run some tests using a common data provider in PHPUnit. See below test: namespace AppBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use AppBundle\Tests\DataProvider\XmlDataProvider; class DefaultControllerTest extends WebTestCase { /** * @dataProvider XmlDataProvider::xmlProvider * @covers ReceiveController::receiveAction() * @param string */ public function testReceive($xml) { $client = static::createClient([], ['HTTP_HOST' => 'mt.host']);

Unit testing algorithms that involve random numbers

試著忘記壹切 提交于 2019-12-22 08:41:35
问题 I'm writting some code about fractals and random terrain generation. Specifically, I'm using the Diamond-Square algorithm as of now. For those of you who don't know, it basically obtains the average of four values, and adds a random number, every step. How wouldI go about testing the result? Should I use a known seed and calculate by hand the average plus the random value, or what? Should I, instead, calculate the result in the code, using the random numbers? Or is there another way? Also,

Two dimensional object array return type - NSubstitute

痴心易碎 提交于 2019-12-22 08:37:12
问题 I get a cast exception System.InvalidCastException : Unable to cast object of type 'System.Object[]' to type 'System.Object[,]'. at Castle.Proxies.ITestProxy.Get2DArray() at Scratch.TestFixture.Get2DArray() in TestTest.cs: line 17 from from the below: [TestFixture] public class TestFixture { [Test] public void Get2DArray() { Substitute.For<ITest>().Get2DArray().Returns(new object[1,1]); } } public interface ITest { object[,] Get2DArray(); } can anyone throw any light on this? I'm thinking it

What are some good examples of open source projects developed in a test-driven fashion?

无人久伴 提交于 2019-12-22 08:28:28
问题 I found Open source projects with good quality tests but I wanted to ask something a bit different. I'm having a hard time visualizing how to build production code using TDD practices, particularly for networked database-driven applications where big chunks of functionality are dependent on one or more external systems. The two main strategies I've seen discussed for accomplishing that are decoupling code from the systems in question and using mocks. However, my intuition is that doing either

pytest to insert caplog fixture in test method

◇◆丶佛笑我妖孽 提交于 2019-12-22 08:13:04
问题 I have the following test class for pytest: class TestConnection(AsyncTestCase): '''Integration test''' @gen_test def test_connecting_to_server(self): '''Connecting to the TCPserver''' client = server = None try: sock, port = bind_unused_port() with NullContext(): server = EchoServer() server.add_socket(sock) client = IOStream(socket.socket()) #### HERE I WANT TO HAVE THE caplog FIXTURE with ExpectLog(app_log, '.*decode.*'): yield client.connect(('localhost', port)) yield client.write(b'hello

When using dependency injection, where do all the new operators go?

江枫思渺然 提交于 2019-12-22 06:06:28
问题 I've been reading about dependency injection, and I understand the basic concept that a method should receive what it needs from its caller rather than creating such items itself. As a result, new operators get removed from the method almost entirely (certain basic objects would be exempt, of course - one example of this I found was for things like StringBuilder s which seem like they'd be insane to have to pass in). My question sounds deceptively simple, but I suspect the answer is actually

how to test or describe endless possibilities?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 04:28:08
问题 Example class in pseudocode: class SumCalculator method calculate(int1, int2) returns int What is a good way to test this? In other words how should I describe the behavior I need? test1: canDetermineSumOfTwoIntegers or test2: returnsSumOfTwoIntegers or test3: knowsFivePlusThreeIsEight Test1 and Test2 seem vague and it would need to test a specific calculation, so it doesn't really describe what is being tested. Yet test3 is very limited. What is a good way to test such classes? 回答1: I would

Should I unit test for multithreading problems before writing any lock?

和自甴很熟 提交于 2019-12-22 04:13:43
问题 I am writing a class that I know that needs a lock, because the class must be thread safe. But as I am Test-Driven-Developing I know that I can't write a line of code before creating a test for it. And I find very difficult to do since the tests will get very complex in the end. What do you usually do in those cases? There is any tool to help with that? This question is .NET specific Someone asked for the code: public class StackQueue { private Stack<WebRequestInfo> stack = new Stack

How can I make jasmine.js stop after a test failure?

自作多情 提交于 2019-12-22 04:01:06
问题 I want the runner to stop after the first failure rather than running all the tests. 回答1: It's a hack, but you can do this by inserting this script before your first test; <script type="text/javascript"> // after every test has run afterEach(function () { // check if any have failed if(this.results_.failedCount > 0) { // if so, change the function which should move to the next test jasmine.Queue.prototype.next_ = function () { // to instead skip to the end this.onComplete(); } } }); </script>

Testing devise views with rspec

◇◆丶佛笑我妖孽 提交于 2019-12-22 03:47:22
问题 I have generated Devise's views running rails g devise:views and would now like to test them. This is what I have come up with: require 'spec_helper' describe "devise/sessions/new" do before do render end it "renders the form to log in" do rendered.should have_selector("form", action: user_session_path, method: :post) do |form| end end end For the render statement it gives me undefined local variable or method 'resource' . After googling around I found that I should add @user.should_receive(