Running a TestNG class via testng.xml in Eclipse (Windows) - eclipse

I have a class named "ATestClass" and it has some methods such as "launchSite", "loginToSite" etc.
Now, I want to control the order of execution of these methods. So, I created an xml file "testng.xml" as below:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Classes" verbose="10">
<test name="ATestClass" preserve-order="true">
<classes>
<class name="ATestClass" >
<methods>
<include name="launchSite" />
<include name="searchAndExport" />
<include name="loginToSite" />
</methods>
</class>
</classes>
</test>
</suite>
Now, my class doesn't care this xml file and executes the methods in alphabetical order. I created both class and xml file in the same package.
Somehow, the class is not able to recognize its corresponding xml config file.
Please help me!

Are you using the latest version of TestNG? Make sure you are.

Related

Error in Target xslt in build.xml for ecllipse

Im trying to include xslt reports in my Testng framework with ant. When I try to execute the the MakeReport target in build.xml I get some error related to classpath saying Reference test.classpath not found . Below is the target code for generating xslt.
<target name="makexsltreport">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${ng.result}/testng-results.xml" style="src/xslt/testng-results.xsl" out="${ws.home}/testng-xslt/index.html"
classpathref="test.c" processor="SaxonLiaison">
<!-- THE ERROR IS IN ABOVE LINE -->
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="classpath">
</classpath>
</xslt>
</target>
Please help on how to solve this issue. i tried everything.
Reference test.classpath not found
means that Ant wasn't able to find the test.classpath path that you have referenced with classpathref. How are you defining that path? If the <path id="test.classpath"> is inside a target then you will need to make your makexsltreport target depend (directly or indirectly) on the one that defines the path.
Also you should not use both a classpathref attribute and a <classpath> element - use one or the other.

Adding junit test single file target to free-form java project in netbeans

I promise, I've read:http://netbeans.org/kb/articles/freeform-config.html
I have a java free-form project that I would like to modify to include a "Test Single File" target to the context menu within Netbeans 7.2
The included link outlines creating an action with the name "test.single" (in order to override Netbeans' Test Single File command) and within that action creation, one must specify an ant target and a context object like so:
<context>
<property>testclass</property>
<folder>${current.dir}</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
So to summarize, I have:
Created the action in project.xml within the ide-actions block:
<action name="test.single">
<target>test-single</target>
<context>
<property>testclass</property>
<folder>${current.dir}</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
Added the ide-action to the context-menu block"
<ide-action name="test.single"/>
Adding this to the free-form project's project.xml file yields a grayed out "test.single" entry in the context menu upon right-clicking on the project name. Further, right clicking on a test class in my src/test directory yields a grayed out "Test Single File" entry.
I've checked and validated the xml and it all seems to check out. What could I be doing wrong?
thanks in advance!
Had the same problem and managed to solve it by cloning the action run.single in by nbproject/project.xml and calling it test.single:
<action name="test.single">
<script>build.xml</script>
<target>test-single</target>
<context>
<property>test.class</property>
<folder>src/java</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
I also changed the property to test.class as we need this in the projects build.xml to run the appropriate test class.
In the main build.xml I have a target test-single:
<target name="test-single" description="Run individual Unit tests" depends="compile, compile-test" >
<junit
printsummary="yes"
errorProperty="test.failed"
failureproperty="test.failed"
haltonfailure="yes"
fork="yes"
showoutput="yes">
<formatter type="plain" usefile="false"/>
<classpath>
<pathelement location="${build.base.classes.dir}" />
<pathelement location="${unit.test.classes.dir}" />
<pathelement location="${junit.dir}" />
</classpath>
<test name="${test.class}Test" todir="${results}">
</test>
</junit>
<fail message="Tests failed!" if="test.failed"/>
</target>
Note that the refers to the property ${test.class}. But when I leave it like that it tries to run the class being tested instead of the JUnit test class. Since this is always called the same as the class being tested with the word "Test" at the end I have written it so that the name is ${test.class}Test.

How can I let CruiseControl.NET/nant run all Unittest projects postfixed with .Test?

In our continuous integration setup, I would like to set up CruisControl.NET to automatically run all our unittests. However, I don't want to have to specify every unittest dll seperately in the configuration.
All the unittest projects are all postfixed with .Test (and all non-unittest projects are not). How can I configure CruiseControl.NET to run all the unittests from these projects (I am using v1.5.7256.1 of CruiseControl.NET)?
My current config attempt:
<nunit>
<path>$(nunit.path)</path>
<assemblies>
<assembly>$(working.dir)\**\*.Test.dll</assembly>
</assemblies>
</nunit>
I'm finding it very difficult to find documentation on this specific nunit element. Most pages I can find talk about using exec, nunit2 or another nunit element or the nunit-console commandline options.
I don't have much experience with managing the build environment and am working on an existing configuration where every assembly was specified separately in the following manner.
<nunit>
<path>$(nunit.path)</path>
<assemblies>
<assembly>$(artifact.dir)\test1.dll</assembly>
<assembly>$(artifact.dir)\test2.dll</assembly>
</assemblies>
</nunit>
Hence my failed attempt using wild cards.
EDIT:
Here is some extra xml of my configuration file to show the context a little bit:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<project name="MyProject">
<!-- whole bunch of other elements -->
<tasks>
<nunit>
<!-- see above -->
</nunit>
</tasks>
</project>
</cruiscontrol>
After Mightmuke's suggestion, I tried replacing the <nunit> element with his suggestion, but got the following exception: Unable to instantiate CruiseControl projects from configuration document. Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration. Unable to load array item 'property' - Cannot convert from type System.String to ThoughtWorks.CruiseControl.Core.ITask for object with value: ""
Then I tried to move the <property> and <foreach> element outside the element. Then I get the exception: Unused node detected: <property name="nunit.filelist" value="" />
I'm now trying to find out more about the <foreach> element and where I can put that, but somehow I find it hard to find any documentation about it.
EDIT2:
I found the documentation of the nunit task I'm using: http://ccnet.sourceforge.net/CCNET/NUnit%20Task.html
I specifies the element to be of type String[]. I'm not sure what that means... but it seems from the example that it just means that it must contain a list of child elements of the same name in Singular form.
PS: I realize this question is getting a bit out of hand... When the whole thing is solved, I'll try to edit it in such a format so that it might be useful to someone else later.
This is an example configuration if you were to use the nunit console.
<property name="nunit.filelist" value="" />
<foreach item="File" property="testfile" verbose="true">
<in>
<items basedir=".">
<include name="${working.dir}\**\*.Test.dll" />
</items>
</in>
<do>
<property name="nunit.filelist" value="${nunitfile.list + ' ' + testfile}" />
</do>
</foreach>
<exec program="nunit-console-x86.exe" failonerror="true" verbose="true">
<arg value="${nunit.filelist}" />
<arg value="/xml=nunit-results.xml" />
<arg value="/nologo" />
<arg value="/nodots" />
</exec>
This hasn't been tested, and there are likely better ways to skin it, but it will hopefully provide a starting point for you.

Include/Exclude buildfiles

How do you do this? Given several build files, I only want to include the ones where the target (specified from the command line) exists. Using target::exists in does not seem to work. Thanks.
<target name="*">
<property name="curr.target" value="${target::get-current-target()}"/>
<nant target="${curr.target}">
<buildfiles>
<include name="*.build" if="${target::exists(curr.target)}"/>
<!-- avoid recursive execution of current build file-->
<exclude name="${project::get-buildfile-path()}" />
</buildfiles>
</nant>
</target>
Using robaker's solution, my final build file looks like this. It does not fail anymore if the target is not found in a certain build file (unlike my previous code).
<project>
<include buildfile="A.build"/>
<include buildfile="B.build"/>
<target name="*">
<nant target="${target::get-current-target()}"/>
</target>
</project>
Why not just use the include task to include all your child build scripts instead?

NAnt - Including source files in a csc task outside of the base directory

I am just starting to pick up NAnt as a replacement for MSBuild in our CruiseControl project.
One of the things we do inside a set of projects is link in a single AssemblyInfo.cs file from outside of the project tree to make versioning easier (it lives in a directory above the project folders).
Is there an obvious way of achieving this in the <sources> section of the <csc> task?
From what I can tell, the <sources> section only supports a single <include> element, which must be underneath the basedir of the task.
I suppose another option would be to copy the single AssemblyInfo.cs file as part of the task prior to calling csc, but wondered whether there was a cleaner way of doing this.
You are not limited to a single <include/> in <sources/>. You can reference whatever you want if you don't specift the basedir property of <sources/>:
<csc target="exe" output="HelloWorld.exe" debug="true">
<sources>
<!-- Will use project dir as base dir -->
<include name="**/*.cs" />
<!-- Absolute path -->
<include name="/tmp/42/*.cs" />
<!-- Relative to project dir -->
<include name="../../Shared/*.cs" />
</sources>
<references>
<include name="System.dll" />
<include name="System.Data.dll" />
</references>
</csc>