carpenter-generator

Carpenter is a framework for unit test generation from runtime data.

License

License

GroupId

GroupId

com.github.tankist88
ArtifactId

ArtifactId

carpenter-generator
Last Version

Last Version

0.0.10
Release Date

Release Date

Type

Type

jar
Description

Description

carpenter-generator
Carpenter is a framework for unit test generation from runtime data.
Project URL

Project URL

https://github.com/tankist88/carpenter-generator
Source Code Management

Source Code Management

https://github.com/tankist88/carpenter-generator

Download carpenter-generator

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tankist88/carpenter-generator/ -->
<dependency>
    <groupId>com.github.tankist88</groupId>
    <artifactId>carpenter-generator</artifactId>
    <version>0.0.10</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tankist88/carpenter-generator/
implementation 'com.github.tankist88:carpenter-generator:0.0.10'
// https://jarcasting.com/artifacts/com.github.tankist88/carpenter-generator/
implementation ("com.github.tankist88:carpenter-generator:0.0.10")
'com.github.tankist88:carpenter-generator:jar:0.0.10'
<dependency org="com.github.tankist88" name="carpenter-generator" rev="0.0.10">
  <artifact name="carpenter-generator" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tankist88', module='carpenter-generator', version='0.0.10')
)
libraryDependencies += "com.github.tankist88" % "carpenter-generator" % "0.0.10"
[com.github.tankist88/carpenter-generator "0.0.10"]

Dependencies

compile (3)

Group / Artifact Type Version
com.github.tankist88 : carpenter-core jar 0.0.12
commons-io : commons-io jar 2.4
com.github.javaparser : javaparser-core jar 2.4.0

test (2)

Group / Artifact Type Version
org.testng : testng jar 6.8
org.mockito : mockito-core jar 2.2.22

Project Modules

There are no modules declared in this project.

carpenter-generator

Build Status Codecov Codacy Badge Maven Central

Carpenter is a framework for unit test generation from runtime data. It useful for unit test coverage of legacy systems. Also it may be useful for coverage new features.

This module generate unit tests from data collected by carpenter-collector.

Other repositories:

File list:

carpenter.properties
carpenter-generator.jar

Example usage:

java -jar carpenter-generator.jar

Example configuration:

# ************************
# Common parameters
# ************************
object.dump.dir=tmp
ut.gen.dir=tmp
data.providers.class.pattern=org.example.util.CommonDataProvider_
# ************************
# Tests will be generated only for classes in this packages
# ************************
test.generation.allowed.packages_1=org.example
# ************************
# Classes in this packages will be ignored by trace collector
# ************************
trace.collect.excluded.packages_1=org.example.webapp.simpleweb.servlet
trace.collect.excluded.packages_2=org.example.webapp.simpleweb.data
# ************************
# Classes in this packages will be ignored by source generator
# ************************
data.providers.excluded.packages_1=net
data.providers.excluded.packages_2=com
data.providers.excluded.packages_3=sun
data.providers.excluded.packages_4=java.lang.ref
data.providers.excluded.packages_5=java.lang.Class.AnnotationData
data.providers.excluded.packages_6=org.eclipse

Output unit tests:

@Generated(value = "org.carpenter.generator.TestGenerator")
public class LibraryServiceGeneratedTest {

    @Spy
    @InjectMocks
    private LibraryService testInstance;

    @Mock
    private org.example.webapp.simpleweb.service.IsbnService isbnService;

    @Mock
    private org.example.webapp.simpleweb.service.SubscribeService subscribeService;

    @Generated(value = "org.carpenter.generator.TestGenerator")
    @Test
    public void testGetBooks_1() throws java.lang.Exception {
        doNothing().when(subscribeService).sendClientNotification(any(ExtPlan.class));
        doNothing().when(subscribeService).setPlan(any(ExtPlan.class));
        doReturn(CommonDataProvider_4.getClient__1305902843()).when(subscribeService).getClient();
        testInstance.getBooks();
        verify(subscribeService, atLeastOnce()).sendClientNotification(any(ExtPlan.class));
        verify(subscribeService, atLeastOnce()).setPlan(any(ExtPlan.class));
        verify(subscribeService, atLeastOnce()).getClient();
    }

    @Generated(value = "org.carpenter.generator.TestGenerator")
    @Test
    public void testGetSummaryStr_1() throws java.lang.Exception {
        doReturn(CommonDataProvider_3.getLibrarySummary_899664243()).when(testInstance).getSummary();
        java.lang.String result = testInstance.getSummaryStr();
        verify(testInstance, atLeastOnce()).getSummary();
        assertEquals(result, CommonDataProvider_4.getString_225853195());
    }

    @Generated(value = "org.carpenter.generator.TestGenerator")
    @Test
    public void testGetSummary_1() throws java.lang.Exception {
        doReturn(CommonDataProvider_2.getArrayList_2118523509()).when(testInstance).getBooks();
        doAnswer(new Answer() {
            private int count = 0;
            private String[] values = {
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941(),
                    CommonDataProvider_1.getString_1114439941()
            };
            @Override
            public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                String result = values[count];
                if(count + 1 < values.length) count++;
                return result;
            }
        }).when(isbnService).getBookISBN(any(Integer.class));
        testInstance.getSummary();
        verify(testInstance, atLeastOnce()).getBooks();
        verify(isbnService, atLeastOnce()).getBookISBN(any(Integer.class));
    }

    @BeforeMethod
    public void init() {
        initMocks(this);
        testInstance.isbnService = isbnService;
        testInstance.subscribeService = subscribeService;
    }
}

Installation

mvn clean install

Contacts

Versions

Version
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1