Reputation: 176
I have a Client/Server application written in Java (client) and C++ (server).
I was wondering if there was a way of using Gtest (or any other testing framework, not necessarily in C++, as long as it's not a Java framework) as a base framework to perform tests on the Java side.
So basically, what I want to achieve is in the following pseudo-code:
// inside MyClass.java
public class MyClass{
public int myMethod(){
return 42;
}
}
//-------------------\\
// inside MyTest.cpp \\
TEST_F(MyJavaClassTest, meaning_of_life)
{
ASSERT_EQUALS(MyClass.myMethod(), 42);
}
//--------\\
// Output \\
[ RUN ] MyJavaClassTest.meaning_of_life
[ OK ] MyJavaClassTest.meaning_of_life (0 ms)
Upvotes: 0
Views: 243
Reputation: 2036
Even if you find such solutions, I would strongly advice against them. The reason is that you will get yet another inter-operability layer between Java and C++ code.
First of all, you will need to somehow interface your Java code to C++ clients (in this case, "client" is your tests). Let's assume you've done that.
Now, what happens when some of your tests fail? Basically, if you had them written in Java, you would have to find out:
If you add another interop layer on top of your Java code, you add another question to those, namely:
From my personal experience (mostly based on mixed C++/C# code bases) such interoperability issues are rare, but very time-consuming once you get into them.
So, unless you're planning to add or maintain a C++ interface over your Java client for production needs, don't go this way. If you don't like JUnit that much, try checking other Java testing frameworks.
And, vice versa, if having a C++ API over Java code is a required feature in your product (which seems unlikely from your description), then C++ tests over Java client would be a "must". But only in such case.
Upvotes: 4