Nunit cannot find nunit-console-runner
Sigh!
After all yesterday’s work, I came back in this morning to find that yes – hoorah, the project had built successfully on the build server.
But oh no! It no longer built on my machine! Not surprising I guess as I spent so much time trying so many things.
The error I got was:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'nunit-console-runner, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.
File name: 'nunit-console-runner, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' at NUnit.ConsoleRunner.Class1.Main(String[] args)
Retracing my steps I found that I had modified the nunit-console.exe.config (found in the nunit \bin\net-2.0 directory).
I had added a supportedRuntime tag:
</startup><supportedRuntime version="v2.0.50727"/></startup>
I removed this and everything is hunky dory again.
If you are getting this error then take a look at that setting. I hope that helps.
NPanday nunit BadImageFormatException
Having got maven to build my C# project including unit tests on my developer machine, I was disheartened to be thwarted by a new lot of errors on the build server.
I took over this project from another developer and so was not certain what the state server configuration was in.
nunit executable in the PATH
The first hurdle was realising that the nunit executable must have it’s location included in the server’s PATH environment variable.
HOORAH, I thought. Now I can move on.
Yeah right!
BadImageFormatException
The unit tests still wouldn’t build. The next error was
ProcessModel: Default DomainUsage: Single
Execution Runtime: Default
Unhandled Exception:
System.BadImageFormatException: Could not load file or assembly 'BBCNewsI.MPS.Tests, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'BBCNewsI.MPS.Tests, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null'
:’(
Why couldn’t maven see my test project?? I can see it! After looking in a lot of wrong places I found the answer. Nunit was running the tests as 64 bit because the build server is 64 bit. As the code is dot net 2.0 and built as 32 bit, this is not good.
Maven pom.xml file
Again I looked in the wrong place. The fix for this is not in nunit but in your maven pom file. You need to force the tests to be run as 32 bit by adding this parameter:
forceX86
So here is how to describe your test. In your pom file, add the parameter to the maven-test-plugin:
<plugin>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>maven-test-plugin</artifactId>
<version>1.4.0-incubating</version>
<configuration>
<forceX86>true</forceX86>
<integrationTest>true</integrationTest>
</configuration>
</plugin>
Ignoring files in subversion
Often you find that you have files that are part of your project that do not belong in version control and you just don’t want to be bugged by subversion highlighting the fact that you haven’t checked them in.
There is documentation on how to ignore these files in the svn book but I found that it lacked a small detail.
Ignoring files globally
There are some files you know that you will never want to check into the repository no matter what project you are working on. Rather than having to mark them to be ignored in every directory of every project that you store in the repo you can instead set a global ignore.
In your subverison client install directory (for unix operation systems it is probably called .subversion) there is a file called config, scroll down to the section marked global-ignores and set the patterns you wish to ignore
global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo
*.rej *~ #*# .#* .*.swp .DS_Store .classpath .settings .project
As you can see, you can use regex to define each pattern. Each pattern is separated by a whitespace.
Setting ignore on a specific directory
N.B. You cannot ignore individual files, you can only set patterns to ignore in a given directory.
First navigate to that directory and issue this command:
svn propedit svn:ignore .
After this you will be presented with a file in which you should type in your pattern(s) to ignore.
It’s pretty simple but I just didn’t spot the fact that you should be putting the patterns in this file rather than specifying the pattern in the svn propedit command itself.
Don’t forget to commit your changes!
Happy ignoring!
Eclipse Package Explorer
Eclipse Indigo
Have you ever had the irritating scenario where all your Java folders (including the empty ones) appear in Package Explorer even though you have correctly created the build path?
I was getting rather irritated by this intermittent “feature” so I asked a friend!
The simple solution is to filter out the unwanted empty folders.
- Click on the downwards arrow in the top right hand side of the Package Explorer window

- Select Filters and then make sure that “Empty Packages” is ticked

Now you will see a much cleaner representation of your project in Package Explorer
android debugging fails
I’m using eclipse as my chosen SDK for android development. It’s great because I feel right at home; I don’t have to learn yet another IDE.
However, I am getting rather frustrated with trying to debug my android application. Quite often eclipse just fails to communicate with the emulator or the device (depending on which I’ve chosen to run the application on).
I found a few tips on the developer.android website which are quite helpful. I would also like to add a discovery of my own. If you have two instances of eclipse running with different android applications, this does not a make a happy debugger! So if you are having trouble with your debugger and you have two projects open, just close one.
Why do I have more than one instance of eclipse running you might ask. Well it is simply to compare working code with new code that is similar but still in the making.
So as promised. Here are the official tips for getting your debugger running again:
developer.android
When communication doesn’t seem to be happening between Eclipse and the emulator, symptoms can include: nothing happening when you press run, the emulator hanging waiting for a debugger to connect, or errors that Eclipse reports about not being able to find the emulator or shell. By far the most common symptom is that when you press run, the emulator starts (or is already running), but the application doesn’t start.
You may find any of these steps will fix the problem and with practice you probably can figure out which one you need to do for your particular issue, but to start with, the safest option is to run through all of them in order:
- Quit the emulator if it is running
- Check that any emulator processes are killed (sometimes they can hang, use ps on unix or mac, or task manager in the process view on windows).
- Quit Eclipse
- From the command line, type:
adb kill-server
- Start Eclipse and try again
And here is the link:
http://developer.android.com/guide/appendix/faq/troubleshooting.html#eclipse
Debugging Cucumber in eclipse
I have had a bit of a ‘mare getting debugging Ruby code in eclipse. Namely getting the ruby-debug-ide gem installed. I’m sure that I’m not the only one.
The problem was that I was unable to run the cucumber feature from eclipse whilst in debug mode, the error was that I hadn’t installed the ruby-debug-ide gem. Unfortunately it seemed to be impossible to install that gem.
I kept getting
ERROR: Failed to build gem native extension
Luckily I found this lovely post so I will share: http://giorgio-ferrara.blogspot.com/2009/11/how-to-enable-ruby-debug-in-rubymine-20_22.html
Reading a file from an Android Test Project
Don’t you just feel like a fool when you can’t even set up your test project to use to read a file? It’s a common approach, you use a local file instead of a remote resource to test your processing of the data.
Well, I had to do a bit of hunting so I thought that I would share it with you. The more posts on this topic, the quicker it will be for the next person who gets stuck on this to find the answer.
So, I was testing a POJO and felt that all I needed was to extend the AndroidTestCase but this assumption was incorrect. In order to access the test project’s own resources you need to extend the InstrumentationTestCase
In my case I stored my test data in res\raw so that I could use a stream reader to convert the data to a simple string. Here’s how I did it:
protected void setUp() throws Exception {
super.setUp();
try{
Resources res = getInstrumentation().getContext().getResources();
InputStream instream = res.openRawResource(R.raw.uk_atom);
...
}catch(Exception e){
Log.d(LOGTAG, e.getMessage());
}
}
Now you are not restricted to using the raw resource there are plenty of other types of resources, take a look at the documentation here: andriod developers
Happy coding!
Java Model Exception when cleaning android project
Android woes
I thought that I would add this little note just in case there is anyone out there who has also suffered this problem. It can occur if you remove an android project from your workspace and then decide to add it again as a new project. In my case I had exported the project from subversion and then deleted the original (for reasons of sanity in my repository).
So the problem occurs when you add the project back to your workspace. I’m presuming that some of the settings get really confused when you try to add a project that used to be part of the workspace. I’m not really concerned with what but more interested in the fix. Here is the error:
Java Model Status [gen [in HelloActivity] does not exist]
It occurs when you try to clean your project and you just get a red cross on your project folder and nowhere else; very irritating!
So the fix
You may only need to remove the following files:
.project
.classpath
.DS_Store (if it exists)
and then clean the project
If this doesn’t work try this:
- backup workspace .metadata file
- Restart eclipse
- In eclipse, from windows menu – preferences re-enter the android SDK location
- Now add your project as an existing android project
You might need to re-import any dependencies and mess about with the ordering after that but otherwise it should have done the job.
Extending FileProducer in Camel 2.2.0
Currently there is no documentation for Apache Camel 2.2.0 on the apache camel website. This makes using the latest version rather more time consuming than desirable. I thought that someone must have posted a howto or a tutorial but I was mistaken
Many of the files have been replaced by generic versions and there isn’t any notes on how to use them. So I’m going to post my discoveries here.
I needed to extend the FileProducer so that I could create a secondary file (putfile) whenever a file is sent. This file is just to inform the system that a file has been created at another location. So I Extended the GenericFileProducer which also required the extension of the FileComponent and the FileEndPoint.
I was puzzled as to what type to use in the generic classes. Taking a look at a signature in the FileComponent clarified the issue:
protected GenericFileEndpoint buildFileEndpoint(String uri, String remaining, Map parameters) throws Exception
So I went ahead and used File as the type.
I wanted to save the putfile to a different location so I did this in the FileProducer by extending it. Here you can see where I have overridden the process method in order that the additional file may be constructed:
@Override
public void process(final Exchange exchange) throws Exception {
try {
process(exchange, false);
} catch (Exception ex) {
if (backupPutFileDir != null) {
log.warn("Error on main server, using backup server. ("+ ex.getMessage() +")");
process(exchange, true);
} else {
throw ex;
}
}
}
@SuppressWarnings("unchecked")
private void process(final Exchange exchange, final boolean useBackupServer) throws Exception {
boolean contentUnchanged = false;
((PutFileEndpoint) getEndpoint()).setUseBackupPath(useBackupServer);
final Object header = exchange.getIn().getHeader(PutFileComponent.EXCHANGE_CAMELFILENAME, String.class);
final String contentFileName = (String) header;
final String transactionId = exchange.getIn().getHeader(TRANSACTION_ID_HEADER, String.class);
if (((PutFileEndpoint) getEndpoint()).checkChanged()) {
String newContents = exchange.getIn().getBody().toString();
String destinationFileName = createFileName(exchange);
File destFile = new File(destinationFileName);
try {
if (destFile.exists()
&& newContents.equals(FileUtils.readFileToString(destFile))) {
contentUnchanged = true;
}
}
catch (Exception e) {
log.info("Unable to compare with destination file, so assuming it has changed");
}
}
if (contentUnchanged) {
log.info("Skipping file "+contentFileName
+" because contents haven't changed.");
txlog.info(transactionId+" SKIPPED "+contentFileName);
} else {
super.process(exchange);
// Now the file has been written by the super above, create the
// corresponding putfile
File dir = (useBackupServer ? backupPutFileDir : putFileDir);
FileUtils.forceMkdir(dir);
File putFile = new File(dir, createPutFileName());
File nameToWriteInPut = new File(dir, contentFileName);
FileUtils.writeStringToFile(putFile, nameToWriteInPut.getPath());
txlog.info(transactionId+" WRITTEN "+contentFileName);
}
}
So how does this class get called at all? Well it all starts from the FileComponent. I’ve extended this too and in order to make use of it you need to add it to your camel context either like this:
Create a file that indicates the class of your component. I wanted the word putfile to point to my PutFileComponent (extention of FileComponent so I put this in the contents of the file:
class=com.bbc.newsi.feeds.common.camel.components.PutFileComponent
Then I saved in this location:
META-INF\services\org\apache\camel\component\putfile
or you can simply add it in code like this:
CamelContext context = new DefaultCamelContext();
context.addComponent("putfile", new PutFileComponent());
Now the method buildFileEndPoint can be used to tie up all the extended classes:
@Override
public GenericFileEndpoint buildFileEndpoint(String uri, String remaining, Map parameters) throws Exception {
// the starting directory must be a static (not containing dynamic expressions)
if (remaining.indexOf("${") != -1) {
throw new IllegalArgumentException("Invalid directory: " + remaining
+ ". Dynamic expressions with ${ } placeholders is not allowed."
+ " Use the fileName option to set the dynamic expression.");
}
File file = new File(remaining);
PutFileEndpoint result = new PutFileEndpoint(uri, this);
result.setFile(file);
GenericFileConfiguration config = new GenericFileConfiguration();
config.setDirectory(file.getPath());
result.setConfiguration(config);
return result;
}
ClickOnce Exception reading manifest
I’ve had ClickOnce blow up on me on more than one occasion and I have to confess that it really does irk me. So much time wasted on what must be a bug in Visual Studio. To be precise VS 2005 (yep I still have projects in version 2.0 of the framework).
So the problem is that after publishing the clickOnce application fails with this error:
Exception reading manifest from<fullPath and name to manifest here>: the manifest may not be valid or the file could not be opened.
+ Deployment manifest is not semantically valid.
+ Deployment manifest cannot specify minimumRequiredVersion for online applications.
I also noticed that the Updates button on the publish tab of my start-up project was disabled – tsk! So I compared the csproj file of a working project and found that the line below the PublishUrl had the value of false in it. So I changed it to true.
<PublishUrl><fullPath and name to manifest here></PublishUrl>
<Install>true</Install>
This fixed the problem.
-
Recent
- Nunit cannot find nunit-console-runner
- NPanday nunit BadImageFormatException
- Ignoring files in subversion
- Eclipse Package Explorer
- android debugging fails
- Debugging Cucumber in eclipse
- Reading a file from an Android Test Project
- Java Model Exception when cleaning android project
- Extending FileProducer in Camel 2.2.0
- ClickOnce Exception reading manifest
- How to get a ListView with expandable controls to resize
- WPF Using a trigger when Validation has error
-
Links
-
Archives
- November 2011 (2)
- September 2011 (2)
- August 2010 (2)
- June 2010 (2)
- March 2010 (1)
- January 2010 (4)
- February 2009 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS
