Replace PHPUnit method `withConsecutive` (abandoned in PHPUnit 10)

I have replaced withConsecutive with the following. $matcher = $this->exactly(2); $this->service ->expects($matcher) ->method(‘functionName’) ->willReturnCallback(function (string $key, string $value) use ($matcher,$expected1, $expected2) { match ($matcher->numberOfInvocations()) { 1 => $this->assertEquals($expected1, $value), 2 => $this->assertEquals($expected2, $value), }; });

How to prevent truncating of string in unit test python

To replace [… chars] and [truncated]… with actual characters (no matter how long, and no matter what the type of the compared values are), add this to your *_test.py file: if ‘unittest.util’ in __import__(‘sys’).modules: # Show full diff in self.assertEqual. __import__(‘sys’).modules[‘unittest.util’]._MAX_LENGTH = 999999999 Indeed, as other answers have noted, setting self.maxDiff = None doesn’t help, … Read more

Rails: How to raise I18n translation is missing exceptions in the testing environment

As of Rails 4.1.0, there’s now a better solution than the 4 year-old answers to this question: add the following line to your config file: config.action_view.raise_on_missing_translations = true I like to set this in the test environment only, but you might also want to set it in development. I would strongly advise against setting it … Read more

Is there a way to execute a teardown function after all tests have been run?

Here is an example implementation of the custom test framework solution mentioned by Masklinn: #![feature(custom_test_frameworks)] #![feature(test)] #![test_runner(custom_test_runner)] extern crate test; use test::{test_main_static, TestDescAndFn}; fn main() {} pub fn custom_test_runner(tests: &[&TestDescAndFn]) { println!(“Setup”); test_main_static(tests); println!(“Teardown”); } #[cfg(test)] mod tests { #[test] fn test1() { println!(“Test 1”) } #[test] fn test2() { println!(“Test 2”) } } This … Read more

pytest: How to get a list of all failed tests at the end of the session? (and while using xdist)

Run pytest with -rf to get it to print a list of failed tests at the end. From py.test –help: -r chars show extra test summary info as specified by chars (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed, (p)passed, (P)passed with output, (a)all except pP. Warnings are displayed at all times except when –disable-warnings is set Here’s … Read more

.detectChanges() not working within Angular test

It turns out this is due to using ChangeDetectionStrategy.OnPush in the component. Using OnPush only allows you to call .detectChanges() one time, so subsequent calls will fail to do anything. I’m not familiar enough with Angular to fully understand why. I was able to produce the required behaviour by overriding the ChangeDetectionStrategy in my TestBed … Read more