[Qt-jambi-interest] Fwd: Re: NullPointerException under TestNG
Mathias
listo.mathias at googlemail.com
Mon Feb 9 11:08:27 CET 2009
José,
thanks for your input on this.
The thread on your problems with JUnit4 is interesting.
However, I think this problem was somehow different.
Adding "QCoreApplication.initialize(new String[0]);" as first line of code
executed does not change anything.
The thing runs when started from the static main() and crashes in the TestNG
test.
Also, if the "QCoreApplication.initialize()" were really required, how come
it works without it when run from the static main()?
Cheers,
Mathias
On Sun, Feb 8, 2009 at 7:22 PM, José Arcángel Salazar Delgado <
arcangel.salazar at gmail.com> wrote:
>
>
> El Sunday 08 February 2009 10:28:26 Mathias escribió:
> > Gentlemen,
> >
> > I'm getting a strange crash when instantiating a QAbstractItemModel sub
> > class when running a TestNG test.
> > Consider this short code example:
> >
> > import com.trolltech.qt.QtBlockedSlot;
> > import com.trolltech.qt.core.QAbstractItemModel;
> > import com.trolltech.qt.core.QModelIndex;
> > import org.testng.annotations.Test;
> >
> > public class SimpleTest {
> >
> > public static class MyModel extends QAbstractItemModel {
> > @QtBlockedSlot
> > public int columnCount(QModelIndex index) { return 0; }
> >
> > @QtBlockedSlot
> > public Object data(QModelIndex index, int i) { return null; }
> >
> > @QtBlockedSlot
> > public QModelIndex index(int i, int i1, QModelIndex index) {
> return
> > null; }
> >
> > @QtBlockedSlot
> > public QModelIndex parent(QModelIndex index) { return null; }
> >
> > @QtBlockedSlot
> > public int rowCount(QModelIndex index) { return 0; }
> > }
> >
> > @Test
> > public void test() {
> > System.out.println(new MyModel());
> > }
> >
> > public static void main(String[] args) {
> > System.out.println(new MyModel());
> > }
> >
> > }
> >
> >
> > When running the static main() method everything works fine, output is
> > something like this:
> > test::SimpleTest$MyModel(0x31c92d8)
> >
> > However, when I run the TestNG test using a TestNG test runner the thing
> > crashes somewhere inside the QAbstractItemModel constructor:
> >
> > java.lang.NullPointerException
> > at
> >
> com.trolltech.qt.internal.MetaObjectTools.buildMetaData(MetaObjectTools.jav
> >a:787) at
> >
> com.trolltech.qt.core.QAbstractItemModel.__qt_QAbstractItemModel_QObject(Na
> >tive Method)
> > at
> >
> com.trolltech.qt.core.QAbstractItemModel.<init>(QAbstractItemModel.java:102
> >) at
> >
> com.trolltech.qt.core.QAbstractItemModel.<init>(QAbstractItemModel.java:98)
> > at test.SimpleTest$MyModel.<init>(SimpleTest.java:25)
> > at test.SimpleTest.test(SimpleTest.java:44)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
> >9) at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
> >l.java:25) at java.lang.reflect.Method.invoke(Method.java:585)
> > at
> org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
> > at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
> > at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
> > at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
> > at
> >
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.jav
> >a:126) at
> > org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110) at
> > org.testng.TestRunner.runWorkers(TestRunner.java:720)
> > at org.testng.TestRunner.privateRun(TestRunner.java:590)
> > at org.testng.TestRunner.run(TestRunner.java:484)
> > ...
> >
> > At first I thought it might be a threading problem, but in this example
> > TestNG runs the test on the main thread...
> >
> > Does anyone have an idea on what might be causing the problem?
> > I heavily depend on TestNG for testing my applications and I would hate
> to
> > not be able to use it for testing the non-GUI parts of the apps (like the
> > models).
> >
> > Cheers,
> > Mathias
>
> Hello.
>
> The problem (I guess) is that you arent calling QApplication or
> QCoreApplication before you try to use a Qt class.
>
> Check this thread. Is a test in Junit, but it can help you.
>
> http://www.mail-archive.com/qt-jambi-interest@trolltech.com/msg00399.html
>
>
>
>
>
>
> -------------------------------------------------------
>
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-jambi-interest/attachments/20090209/e8834cc8/attachment.html
More information about the Qt-jambi-interest
mailing list