Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing C++ code using Java

I have inherited a huge c++ codebase with some integration tests. This is a critical system which feeds data to a lot of downstream systems. As the tests are very unreliable our team is not able to push changes confidently.

We want to introduce some tests in the system but most of the developers have Java background. What options do we have ?

1) Learn C++

2) Use JNI : Not sure how easy that is

like image 364
NRS Avatar asked Dec 14 '11 05:12

NRS


People also ask

What is Java unit testing?

What Is Java Unit Testing? Java unit testing is the practice of applying the unit testing method to individual units of Java source code

What is the difference between JUnit and unit testing?

A unit test generally only tests out one small piece of functionality, and you’ll usually write a bunch of unit tests to make sure your code handles a variety of conditions. By running unit tests on your code, you can be more confident that your change didn’t break anything. JUnit is a library that helps us write unit tests.

What is the best unit testing framework for C code?

CppUnit. The premier unit testing framework for C++; you can also use it to test C code. It is stable, actively developed, and has a GUI interface. The primary reasons not to use CppUnit for C are first that it is quite big, and second you have to write your tests in C++, which means you need a C++ compiler.

What are unit tests in Python?

Unit tests are small programs that you write to test out your “real” code. A unit test generally only tests out one small piece of functionality, and you’ll usually write a bunch of unit tests to make sure your code handles a variety of conditions. By running unit tests on your code, you can be more confident that your change didn’t break anything.


1 Answers

Using JNI adds another layer of complexity and still you will learn C++ - I wouldn't recommend it if you don't want to use C++.

Depending on what the C++ system does you can choose different testing strategies. In my experience I had a system which was responsible for data processing and all the data was sent via network. In this case the tests were done in python:

  1. we checked the protocol
  2. we checked the processed data validity given a certain input (also controlled in python)

My case was a lucky one since the communication was done via a network connection (we could literally use whatever language we wanted).

If you cannot use anything else but C++ I think you will have to do it in C++ (and not Java + JNI + C++).

like image 126
INS Avatar answered Oct 07 '22 10:10

INS