Unit test can't find class to test

unit testing
integration testing
what is unit testing with example
unit testing guidelines
unit testing c#
system testing
unit test python
unit testing tutorial

I've got a stock standard class call GeoRssParserDelegate which needs to be tested.

In my swift unit test I've got this:

func testParser()
{
    var bundle = NSBundle(forClass:GeoRssParserTest.classForKeyedArchiver())
    var path = bundle.pathForResource("test", ofType: "xml")
    let data = NSData.dataWithContentsOfFile(path, options: NSDataReadingOptions.DataReadingMapped, error: nil)
    let xmlParser = NSXMLParser(data:data)
    let delegate = GeoRssParserDelegate() <-- Compiler fails here
    var bStatus = xmlParser.parse()
    XCTAssertTrue(bStatus, "Parse failed", file: __FILE__, line: __LINE__)        
}

The compiler fails on the line highlighted above. The compiler error is Use of unresolved idenitifier GeorRssParserDelegate

This class does exist and builds with the product itself. Is anything special required?

You have to import your application's module into your unit test. This is usually your app name. For example, if your app name is GeoRssParser the import statement would be:

import GeoRssParser

Unit Testing Tutorial: What is, Types, Tools, EXAMPLE, In this case, a unit test can make an attempt to receive and analyze that network traffic. Or, if the hardware components are connected with a wire, the unit test can � Unit Testing Is Not About Finding Bugs In most cases, unit tests are not an effective way to find bugs. Unit tests, by definition, examine each unit of your code separately. But when your

Solution for Xcode 8 and UP which works for me:

@testable import Product_Module_Name

note: not the target name but product's name.

Regarding answers above: making without @testable will require to make classes and methods public which changes the design of the app architecture. if you don't want to change it better to use this solution so you won't need to make changes to class being public or no.

Many thanks to this answer

Unit Testing and Coding Best Practices for Unit Tests: A Test-Driven , But “mainstream” does not mean “universal.” Plenty of folks still do not have comfort with or even exposure to the unit testing practice. And yet, a� At a high-level, unit testing refers to the practice of testing certain functions and areas – or units – of our code. This gives us the ability to verify that our functions work as expected.

If the class you're testing is compiled into another target (such as your application, as opposed to the test bundle), make sure that the class or struct you're trying to use is marked public -- the default access visibility doesn't allow for cross-target testing.

Unit Testing Tutorial: 6 Best Practices to Get Up To Speed, A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, � Unit testing simply verifies that individual units of code (mostly functions) work as expected. Usually you write the test cases yourself, but some can be automatically generated. The output from a test can be as simple as a console output, to a " green light " in a GUI such as NUnit, or a different language-specific framework.

If you're using brand new XCode 7 (as of Jul 21, 2015), simply write: @testable import GeoRssParserDelegate

Source: http://natashatherobot.com/swift-2-xcode-7-unit-testing-access/

What Is Unit Testing?, UNIT TESTING is a level of software testing where individual units/ How? If you do not have unit testing in place, you write your code and perform that fuzzy� Unit tests are standalone, can be run in isolation, and have no dependencies on any outside factors such as a file system or database. Repeatable . Running a unit test should be consistent with its results, that is, it always returns the same result if you do not change anything in between runs.

Just add the class you are testing to Target -> Build Phases -> Compile Sources

It's how I fixed my problem.

Unit Testing, Rerun unit tests when you make changes to test that your code is still working correctly. Visual Studio Enterprise can do this automatically with� UNIT TESTINGis a level of software testing where individual units/ components of a software are tested. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part of any software. It usually has one or a few inputs and usually a single output.

Unit testing fundamentals, You can use Test Explorer to run unit tests from the built-in test framework ( MSTest) or from third-party test frameworks. You can group tests into� Unit tests test individual software components and methods. Unit tests should only test code within the developer’s control. They should not test infrastructure concerns. Infrastructure concerns include databases, file systems, and network resources.

Get started with unit testing, Some users will find that they have existing test code that they would like to run from unittest , without converting every old test function to a TestCase subclass. For� A Unit Test is a code written by any programmer which test small pieces of functionality of big programs. Performing unit tests is always designed to be simple, A "UNIT" in this sense is the smallest component of the large code part that makes sense to test, mainly a method out of many methods of some class.

unittest — Unit testing framework — Python 3.8.4rc1 documentation, Unit testing involves breaking your program into pieces, and subjecting each piece to a series of tests. Usually tests are run as separate�

Comments
  • Maybe silly question: But are you sure it’s a class and not a protocol? Either way you probably need to post more of your code.
  • I want to give this answer 1000 up votes. THANK YOU.
  • Not sure if it's always the case, but this only worked for me when i prefixed the import statement with @testable
  • IMHO this should be the right answer in addition to James´s answer. Marking the tested Class or struct as public is necessary. Otherwise the Test-target will not find it. And for sure it has to be imported...
  • In Xcode 6.3 beta 3, I not only had to mark each class to be tested as public, but each and every constituent class or instance function tested as well. Cumbersome.
  • This is no longer the case as you can use @testable in Swift 2.0
  • does this work for anyone? for me it gives an error in Xcode 8: No such module 'class_name'
  • this solution works well but it's not a good design for the app to include the classes of app target to tests target
  • @testable import is the way to go, adding files to test target was how we used to do in Objective-C, but not swift.