How can I time a code segment for testing performance with Pythons timeit?

You can use time.time() or time.clock() before and after the block you want to time. import time t0 = time.time() code_block t1 = time.time() total = t1-t0 This method is not as exact as timeit (it does not average several runs) but it is straightforward. time.time() (in Windows and Linux) and time.clock() (in Linux) are … Read more

How do you print in a Go test using the “testing” package?

The structs testing.T and testing.B both have a .Log and .Logf method that sound to be what you are looking for. .Log and .Logf are similar to fmt.Print and fmt.Printf respectively. See more details here: http://golang.org/pkg/testing/#pkg-index fmt.X print statements do work inside tests, but you will find their output is probably not on screen where … Read more

How to configure “Shorten command line” method for whole project in IntelliJ

Inside your .idea folder, change workspace.xml file Add <property name=”dynamic.classpath” value=”true” /> to <component name=”PropertiesComponent”> . . . </component> Example <component name=”PropertiesComponent”> <property name=”project.structure.last.edited” value=”Project” /> <property name=”project.structure.proportion” value=”0.0″ /> <property name=”project.structure.side.proportion” value=”0.0″ /> <property name=”settings.editor.selected.configurable” value=”preferences.pluginManager” /> <property name=”dynamic.classpath” value=”true” /> </component> If you don’t see one, feel free to add it yourself <component … Read more

toBe(true) vs toBeTruthy() vs toBeTrue()

What I do when I wonder something like the question asked here is go to the source. toBe() expect().toBe() is defined as: function toBe() { return { compare: function(actual, expected) { return { pass: actual === expected }; } }; } It performs its test with === which means that when used as expect(foo).toBe(true), it … Read more

When should I use Debug.Assert()?

In Debugging Microsoft .NET 2.0 Applications John Robbins has a big section on assertions. His main points are: Assert liberally. You can never have too many assertions. Assertions don’t replace exceptions. Exceptions cover the things your code demands; assertions cover the things it assumes. A well-written assertion can tell you not just what happened and … Read more

How to `go test` all tests in my project?

This should run all tests in current directory and all of its subdirectories: $ go test ./… This should run all tests for given specific directories: $ go test ./tests/… ./unit-tests/… ./my-packages/… This should run all tests with import path prefixed with foo/: $ go test foo/… This should run all tests import path prefixed … Read more

Test process.env with Jest

The way I did it can be found in this Stack Overflow question. It is important to use resetModules before each test and then dynamically import the module inside the test: describe(‘environmental variables’, () => { const OLD_ENV = process.env; beforeEach(() => { jest.resetModules() // Most important – it clears the cache process.env = { …OLD_ENV … Read more

Making the Android emulator run faster

Official web page ~50% faster Windows: Install “Intel x86 Emulator Accelerator (HAXM)” => SDK-Manager/Extras Install “Intel x86 Atom System Images” => SDK-Manager/Android 2.3.3 Go to the Android SDK root folder and navigate to extras\intel\Hardware_Accelerated_Execution_Manager. Execute file IntelHaxm.exe to install. (in Android Studio you can navigate to: Settings -> Android SDK -> SDK Tools -> Intel … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)