Sign in Join
Wiki copytemporary

Feature Ideas/UnitTests: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Feature Ideas/UnitTests

OldNewLine
1+\
2+\
3+= Feature idea - Eclipse-style unit tests. =
4+
5+## Main idea
6+
7+The main idea is to **have ability to write and run Unit tests from a subpackage of main project**. This is to avoid creating a special project specifically for UnitTests. By this way, creation and running of UnitTests will be significantly simplified.
8+
9+IMHO, **Unit Tests are very important**. I also consider, that currently UnitTests support in Lazarus is very uncomfortable. And I believe, that it's one of the most important factors, or even **the most important which limits dissemination and distribution of Lazarus and FreePascal**.
10+
11+## Introduction and references
12+
13+I decided to write my feature idea after the following discussions on the forum:
14+
15+[1](http://lazarus.freepascal.org/index.php/topic,15681.0.html) [2](http://lazarus.freepascal.org/index.php/topic,15733.0.html)
16+
17+I consider that You are familiar with concept of unit testing. You can read about Unit tests on Wikipedia: [Unit testing on wikipedia](http://en.wikipedia.org/wiki/Unit_testing)
18+
19+If you are not familiar, please read some more articles about software testing in general (for example, [Software Testing on Wikipedia](http://en.wikipedia.org/wiki/Software_testing)) and why unit tests are so important and why people need them (e.g., [Purpose of unit testing](http://simpleprogrammer.com/2010/10/15/the-purpose-of-unit-testing/)).
20+
21+## Example: JUnit tests in Eclipse Maven Project
22+
23+Let me show, how it is implemented in Eclipse Maven Project (using screenshots from Package Explorer in Eclipse).
24+
25+<figure>
26+<img src="EclipseMavenProjectStructure.jpg" title="EclipseMavenProjectStructure.jpg" />
27+<figcaption>EclipseMavenProjectStructure.jpg</figcaption>
28+</figure>
29+
30+Here is a sample project structure of Eclipse Maven Project. There are several packages in one project. Main program code is located in src/main/java. And Unit tests are located in the same project, but as a separated package - src/test/java. Physically, it's different folders on the filesystem.
31+
32+<figure>
33+<img src="EclipseMavenRunAsJUnitTest.jpg" title="EclipseMavenRunAsJUnitTest.jpg" />
34+<figcaption>EclipseMavenRunAsJUnitTest.jpg</figcaption>
35+</figure>
36+
37+So, it's very easy to create and run UnitTests for an IDE user. All the user need is:
38+
39+- create a new Unit Test class under src/test/java, which will test functionality of one of classes under src/main/java. Both **main classes and Unit tests are in the same project here**
40+- write a test
41+- right click on individual test or the whole test package and choose Run --\> Run as JUnit test
42+- test(s) will be runned, results and stack trace (in case of exception) will be presented.
43+
44+\
45+**Note: Maven features - not directly relevant to the main feature idea of this page.**
46+
47+*There are also 2 resource folders - src/main/resources and src/test/resources. This is a cool feature of Maven. For example, if your class uses my_property_file.txt to load properties, you can have 2 files with this filename, but with different content in main/resources and test/resources. Thus, when you will run one of classes (in Java, one project can have several runnable classes, not just 1 program unit; class could be runnable as Application if it has method main()) in the src/main, it will use property file from (will look for my_property_file.txt in) src/main/resources. But, if you run a JUnit test of the same class from src/test, the same class will load properties from (will look for my_property_file.txt in) src/test/resources.*
48+
49+## Conclusion
50+
51+- Unit testing is very important concept widely used by all developers.
52+- Support for unit testing is important factor for any IDE for any programming language.
53+- I suggest that unit tests are implemented very comfortable in Eclipse (especially, when using Maven - e.g., to have different properties while running the main program and testing).
54+- I also believe, that if it will be possible **for user** (does not matter how it will be exactly implemented in Lazarus code) to create and run unit tests in the same project with the main program, it could significantly increase popularity of Lazarus. Also it will simplify work of many developers.
55+
56+---
57+*From the Free Pascal wiki, page "Feature Ideas/UnitTests", as it stood on 2012-06-06 after a change by Chronos, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
58+Category: Proposals

Back to history