Why won't resharper find my unit tests? - nunit

For some reason when I open a new solution Resharper always refuses to find unit tests. I spend half an hour struggeling/rebuilding/poking until suddenly Resharper magically finds my unit tests. Once they are found it runs them fine every time.
Test example:
using NUnit.Framework;
namespace NamespaceOfTheCodeToTest.Test
{
[TestFixture]
public class FunctionalityTest
{
[Test]
public void Scenario_Input_Result()
{
}
}
}
I am using RESHARPER->Unit Tests->Run All Tests from Solution
What am I doing wrong here?

It seems the problem was NUnit test adapter was not installed. After installing that visual studio extension all tests where found instantly.
Edit: a better solution is to use "Run Unit Tests" on the test project, folder with test projects or solution.

Related

Nunitlite-runner.exe - Dll file has no TestFixtures

I'm trying run tests from nunitlite-runner.exe but i got Error message
1) Invalid : /myfile.dll
Has no TestFixtures
I have in source code
[TestFixture]
public class MyClassName
{
[Order(1)]
[Test]
public void Case1()
{
//
}
[Order(2)]
[Test]
public void Case2()
{
//
}
}
How can i fix code or run my tests?
I got this problem with nunit3-console.exe. I had, in my enthusiasm to upgrade to the latest and greatest, updated my NUnit project references to the latest version (3.9 at this writing), along with my console exe (3.7). But it seems that the console exe is a build or two behind the core libraries, so you can't reference a later version of NUnit than the version you have of the console exe.
I downgraded my NUnit project reference to 3.7, and that fixed it for me.

ScalaTest and SBT: Reporting progress of test suite?

I am using ScalaTest and have a test suite that contains many tests, and each test can take about a minute to run.
class LargeSuite extends FunSuite {
test("Name of test 1") { ... }
...
test("Name of test n") { ... }
}
As is usual with running ScalaTest tests from the SBT console, nothing is reported to the screen until each test in the FunSuite has been run. The problem is that when n is large and each test is slow to run, you do not know what is happening. (Running top or Windows Task Manager and looking for the CPU usage of Java is not really satisfactory.)
But the real problem is when the build is run by Travis CI: Travis assumes that the build has gone wrong and kills it if 10 minutes pass and nothing is printed to the screen. In my case, Travis is killing my build, even though the tests are still running, and each individual test in a FunSuite does not require 10 minutes (although the entire suite does require more than 10 minutes because of the number of tests).
My first question is therefore this: how can I get ScalaTest to report on progress to the console after each test in FunSuite, in an idiomatic way?
My partial solution is to use the following trait as a mixin, which solves the problem with Travis:
trait ProgressConsolePrinter extends BeforeAndAfterEach with BeforeAndAfterAll {
self: Suite =>
override def beforeAll: Unit = {
Console.print(s"$suiteName running")
Console.flush
}
override def afterEach: Unit = {
Console.print(".")
Console.flush
}
override def afterAll: Unit = {
Console.println
Console.flush
}
}
But I understand that using Console to print to the SBT console is not entirely reliable (Googling this seems to somewhat confirm this from the experiences of others).
Also (i) anything you print from Console does not go via SBT's logger, and is therefore not prefixed with [info], and (ii) when trying the above, the messages printed from Console are jumbled up with other messages from SBT. If I was able to use the proper logger, then neither of these things would happen.
My second question is therefore this: How can I print to an SBT logger from within a test in ScalaTest?
To get ScalaTest to report to the console after each test within SBT, add
logBuffered in Test := false
to your build configuration. (See the SBT docs.)
For general logging purposes within SBT, you can use an instance of sbt.util.Logger obtained from streams.value.log within an SBT task as described here. Wilson's answer below can be used if logging is required from the test code.
(I'm answering my own question two years later, but this is currently the first hit on Google for "ScalaTest sbt progress".)
This may be helpful for your second question.
To log like that you must use scala logging. You must add scala logging as a test dependency, extend some of its logging classes (suggest LazyLogging) and then call logger.info("Your message").

How to integrate web service (soap) with JUnit

I am having few web services and working good with soapUI tool. I am trying to run as a suite. I have soapUI, junit and all other necessary libraries added to eclipse and system path has been setup to : soapUI.Junit = C://Doc and Sett/mkd/soapUI 4.2/bin/.
I have written #Before, #Test and #after methods. In #Test I have code something like below:
#Test
public void somex() {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile( "src/dist/sample-soapui-project.xml" );
runner.run();
}
But this code doesn't work. It is not able to recognise SoapUITestCaseRunner. Can someone help me with solution, please.?
you should add soapui-a.b.c.jar(e.g. soapui-2.0.2.jar) to the classpath.then problem will be solved.

Building and loading file in NUnit

I am following a book called "The Art of Unit Testing". I have reached a point where I need to test my test method that I have writtent using NUNit. The author instructs to build the project and then locate the path to the assembly file that was built and give the path to NUnit for testing.
My problem is that I cant seem to get this Assembly file path. Where is it located?
Plus, when I run my code, I am getting the following error:
Error 2 Program 'c:\Users\Documents\Visual Studio 2012\Projects\Loganalyzer\Loganalyzer\obj\Debug\Loganalyzer.exe' does not contain a static 'Main' method suitable for an entry point c:\users\documents\visual studio 2012\Projects\Loganalyzer\Loganalyzer\CSC Loganalyzer
Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loganalyzer
{
public class LogAnalyzer
{
public bool IsValidLogFileName(string fileName)
{
if (!fileName.EndsWith(".SLF"))
{
return false;
}
return true;
}
}
}
I am following the exact example that's in the book but cant get it to work as you can see. I will appreciate your help folks.
using Loganalyzer;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogAnalyzerTest
{
[TestFixture]
class LogAnalyzerTest
{
[Test]
public void IsValidFileName_validFile_ReturnsTrue()
{
//Arrange ( Arranges objects, creating and setting them up as necessary).
LogAnalyzer analyzer = new LogAnalyzer();
//Act
bool result = analyzer.IsValidLogFileName("whatever.SLF");
//Assert ( Asserts that something is as expected)
Assert.IsTrue(result, "file name should be valid");
}
}
}
It seems as though you're trying to run your class project Loganalyzer, but you'll probably be wanting to use some sort of test runner. I prefer TestDriven.net.
NUnit is just the testing framework (very simplified, it specifies the rules for how to set up tests, etc).
What you need is some application or plugin to actually run them. You run the tests in the concole runner, or the GUI runner that come with NUnit for example, or in TestDriven.net (which I've heard is excellent).
Personally, I use the runner that comes with Resharper (although that is only free to try for a month or so).
The point is that you don't have an executable project, but rather a class library, containing stuff to test. The runner runs your tests, which in turn, call your code.
If you want to use the native nunit runner you typically use a class like this
static class NUnitLauncher
{
[STAThread]
static void Main()
{
AppEntry.Main(new[] { Assembly.GetExecutingAssembly().Location });
}
}
You'll also have to have it set as the start-up object (in the project's properties).
You'll also need to reference nunit-gui-runner.dll which you can find in the nunit install directory (normally program files). Mine is at
C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\lib
The native nunit runner has it's problems but I find the resharper (6.1) test runner is unstable when debugging - it sometimes bombs out randomly. It also doesnt understand all the different types of parameterised tests you can have in nunit. Hopefully this isnt the case in the newer versions - it's got a much nicer UI.
The problems you describe above are two seperate things - one sounds like it is because you dont have a startup object set; the other sounds like it is confusion about what an assembly is. The executable that gets produced when you compile will contain an assembly - if you point nunit at that then it should work (assuming it has some nunit stuff in there (eg stuff tagged up with [Test] etc))

TeamCity SpecFlow NUnit Watin and ApartmentState STA

Im trying to get our specflow watin tests to run on our new teamcity server. The problem is that I cant get the built in nunit runner to run tests in appartmentstate STA.
We used this configuration earlier, which works with other testrunners:
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
But the TeamCity NUnit test runner doesnt seem to pick up on this config. We have other config sanity tests in place, so we know the testrunner reads the configuration for our test project atleast.
There's the alternative to use the RequiresSTA attribute like so:
[Test, RequiresSTA]
public void ShouldRunThreadApartmentStateSTAWith()
{
Assert.AreEqual(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
}
But since the NUnit tests are generated by SpecFlow, I don't have control over how these attributes are set.
How can I get this setup to work?
Found the answer.
Setting the RequireSTA attribute in AssemblyInfo.cs makes the configuration obsolete.
[assembly:RequiresSTA]
The NUnit tests generated by SpecFlow is a partial class definition, so simply create another partial class definition in another file that has the attributes on it.