testing interview questions

Top 15 testing interview questions

20971 Jobs openings for testing

How to emulate GPS location in the Android Emulator?

I want to get longitude and latitude in Android emulator for testing.

Can any one guide me how to achieve this?

How do I set the location of the emulator to a test position?

Source: (StackOverflow)

Rspec: "array.should == another_array" but without concern for order

I often want to compare arrays and make sure that they contain the same elements, in any order. Is there a concise way to do this in RSpec?

Here are methods that aren't acceptable:


For example:

array.to_set.should == another_array.to_set

This fails when the arrays contain duplicate items.


For example:

array.sort.should == another_array.sort

This fails when the arrays elements don't implement #<=>

Source: (StackOverflow)

When should I use Debug.Assert()?

I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently.

Our production code contains no asserts whatsoever and my question is this...

Should I begin using Asserts in our production code? And if so, When is its use most appropriate? Would it make more sense to do

Debug.Assert(val != null);


if ( val == null )
    throw new exception();

Source: (StackOverflow)

C++ static code analysis tool on Windows [closed]

What C++ static code analysis tool do you know of for Microsoft Windows development, and what main features does it offer?

Please state whether a particular tool relies on cygwin, and whether its FOSS, free or requires purchase.

Similar Question: What open source C++ static analysis tools are available?

Here is the summary of current state:

  1. PreFAST found in the Windows Driver Kit
  2. CppCheck
  3. Coverity
  4. PVS-Studio
  5. Oink
  6. Klocwork Insight
  7. PC-Lint
  8. CppDepend
  9. Goanna
  10. Sentry
  11. Visual Studio Team System
  12. Understand
  13. cccc
  14. Cqual++
  15. Flawfinder
  16. DMS Software Reengineering Toolkit
  17. Vera++
  18. Source Monitor
  19. Stack (source code at github)

Source: (StackOverflow)

How to make junior programmers write tests? [closed]

We have a junior programmer that simply doesn't write enough tests.
I have to nag him every two hours, "have you written tests?"
We've tried:

  • Showing that the design becomes simpler
  • Showing it prevents defects
  • Making it an ego thing saying only bad programmers don't
  • This weekend 2 team members had to come to work because his code had a NULL reference and he didn't test it

My work requires top quality stable code, and usually everyone 'gets it' and there's no need to push tests through. We know we can make him write tests, but we all know the useful tests are those written when you're into it.

Do you know of more motivations?

Source: (StackOverflow)

How to load db:seed data into test database automatically?

I'm attempting to use the new standard way of loading seed data in Rails 2.3.4+, the db:seed rake task.

I'm loading constant data, which is required for my application to really function correctly.

What's the best way to get the db:seed task to run before the tests, so the data is pre-populated?

Source: (StackOverflow)

Sharing Test code in Maven

How can you depend on test code from another module in Maven?

Example, I have 2 modules:

  • Base
  • Main

I would like a test case in Main to extend a base test class in Base. Is this possible?

Update: Found an acceptable answer, which involves creating a test jar.

Source: (StackOverflow)

All Ruby tests raising: undefined method `authenticate' for nil:NilClass

Most of my tests are raising the following and I don't understand why. All methods call raise the 'authenticate' error. I've checked the code if there was a method called "authenticate" but there is no such method.

  1) Admin::CommentsController handling GET to index is successful
     Failure/Error: get :index
     undefined method `authenticate!' for nil:NilClass
     # ./spec/controllers/admin/comments_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

  124) PostsController handling GET for a single post should render show template
     Failure/Error: get :show, :year => '2008', :month => '01', :day => '01', :slug => 'a-post'
     undefined method `authenticate' for nil:NilClass
     # ./app/controllers/application_controller.rb:18:in `set_current_user_for_model'
     # ./spec/controllers/posts_controller_spec.rb:131:in `do_get'
     # ./spec/controllers/posts_controller_spec.rb:140:in `block (3 levels) in <top (required)>'

The project can be found over there => https://github.com/agilepandas/enki in case you'd like to run the tests your self.

Source: (StackOverflow)

Best way to compare 2 XML documents in Java

I'm trying to write an automated test of an application that basically translates a custom message format into an XML message and sends it out the other end. I've got a good set of input/output message pairs so all I need to do is send the input messages in and listen for the XML message to come out the other end.

When it comes time to compare the actual output to the expected output I'm running into some problems. My first thought was just to do string comparisons on the expected and actual messages. This doens't work very well because the example data we have isn't always formatted consistently and there are often times different aliases used for the XML namespace (and sometimes namespaces aren't used at all.)

I know I can parse both strings and then walk through each element and compare them myself and this wouldn't be too difficult to do, but I get the feeling there's a better way or a library I could leverage.

So, boiled down, the question is:

Given two Java Strings which both contain valid XML how would you go about determining if they are semantically equivalent? Bonus points if you have a way to determine what the differences are.

Source: (StackOverflow)

How to get started on TDD with Ruby on Rails? [closed]

I am familiar with the concepts (took testing classes in college), but I am not sure how to really use them yet since I never worked on a "real" TDD project.

I am about to start the development of a project using Ruby on Rails (most likely using 2.3). This application will be used to manage data, users and some files. It won't be too complicated at first but might scale a lot in the next 6 months so I feel this is the right time to get more into TDD.

I've got a basic idea on how to do it, but I still need some pointers and advices:

  • What Ruby on Rails TDD 101 article should I read?

  • What do I need to test?

  • What gem/plugin should I use?

  • Should I use rspec? Something else?

  • Once I've got all my testing classes, how do I go and deploy them? (e.g.: Continual Integration)

  • How time consuming TDD really is?

  • Do I need to read a book about this or can I get everything just by playing around with it and reading online tutorials? If I need to read a book, what book?

I like learning with examples so could someone tell me how I would go and take a TDD approach to solve this issue:

I have Companies. I have Contacts. A contact can be linked to 1 company. A company can have multiple contacts. I want to create ways to create contacts, companies and link contacts to companies.

You don't have to use this example in your answer but it would help :)

Source: (StackOverflow)

Exact time measurement for performance testing [duplicate]

This question already has an answer here:

What is the most exact way of seeing how long something, for example a method call, took in code?

The easiest and quickest I would guess is this:

DateTime start = DateTime.Now;
    // Do some work
TimeSpan timeItTook = DateTime.Now - start;

But how exact is this? Are there better ways?

Source: (StackOverflow)

javascript test for existence of nested object key

If I have a reference to an object -

var test = {};

that will potentially (but not immediately) have nested objects, something like -

{ level1:{level2:{level3:'level3'}} };

what is the best way to test for the existence of keys in the most deeply nested objects?

This -


returns 'undefined', but this -



I'm currently doing something like this -

if(test.level1 && test.level1.level2 && test.level1.level2.level3) {

but I was wondering if there's a better way.

Source: (StackOverflow)

Jasmine - How to write a test which expects an Error to be thrown

I'm trying to write a test for the Jasmine Test Framework which expects an error. At the moment I'm using a Jasmine Node.js integration from GitHub.

In my Node module I have the following code:

throw new Error("Parsing is not possible");

Now I try to write a test which expects this error:

describe('my suite...', function() {
    it('should not parse foo', function() {
        expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible"));

I tried also Error() and some other variants and just can't figure out how to make it work.

Source: (StackOverflow)

How to develop and test an app that sends emails (without filling someone's mailbox with test data)? [closed]

I have a lot of apps that send email. Sometimes it's one or two messages at a time. Sometimes it's thousands of messages.

In development, I usually test by substituting my own address for any recipient addresses. I'm sure that's what everybody else does, until they get fed up with it and find a better solution.

I was thinking about creating a dummy SMTP server that just catches the messages and dumps them in a SQLLite database, or an mbox file, or whatever.

But surely such a tool already exists? How do you test sending email?

Source: (StackOverflow)

What is Unit test, Integration Test, Smoke test, Regression Test?

What is Unit test, Integration Test, Smoke test, Regression Test and what are the differences between them? And Which tools can I use for each of them?

For example I use JUnit and NUnit for Unit testing and Integration Testing. Are there any Smoke Test or Regression Test tools?

Source: (StackOverflow)