Skip to content

Increase unit test coverage in package "core"#50

Merged
DaRoli merged 1 commit into
Dynatrace:masterfrom
DaRoli:feature/unittest-core
Feb 7, 2018
Merged

Increase unit test coverage in package "core"#50
DaRoli merged 1 commit into
Dynatrace:masterfrom
DaRoli:feature/unittest-core

Conversation

@DaRoli

@DaRoli DaRoli commented Feb 5, 2018

Copy link
Copy Markdown
Contributor

No description provided.

@stefaneberl stefaneberl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback regarding tests:

  • Please remove the "test" prefix from method names, since in the past @thomasgrassauer and I agreed to leave this out. Reason - The classes themselves already do contain the Test word in them and therefore this info is redundant.

Other than that there are several minor comments which are only intended as information about some shortcut methods.


// create a valid session
final Session session = openKit.createSession("127.0.0.1");
assertThat(session, not(nullValue()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.hamcrest.Matchers.notNullValue -> mean it can be used like

assertThat(session, notNullValue());


// User has forgotten to initialize => shall not throw an exception
final Session session = openKit.createSession("127.0.0.1");
assertThat(session, not(nullValue()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(session, notNullValue());

final SessionImpl session2impl = (SessionImpl)session2;

// verify that the two sessions exist and are not the same
assertThat(session1impl, not(session2impl));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would make sense to test for

assertThat(session1impl, not(sameInstance(session2impl)));

This makes clear, that both variables shall not be the same instance.

assertThat(session1impl, not(session2impl));
}

private Configuration createTestConfig() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be a setUp method


// child leaves immediately
final Action retAction = childAction.leaveAction();
assertThat(retAction, is(equalTo((Action) rootAction)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(retAction, is(sameInstance(rootAction)));


// test the constructor call
final WebRequestTracerURLConnection conn = new WebRequestTracerURLConnection(beacon, action, urlConnection);
assertThat(conn, not(nullValue()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(conn, notNullValue());


// verify that the tag is now set
existingTag = urlConnection.getRequestProperty(OpenKitConstants.WEBREQUEST_TAG_HEADER);
assertThat(existingTag, not(nullValue()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(existingTag, notNullValue());

assertThat(session.isEmpty(), is(true));
}

private Beacon createTestBeacon() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method can be made static


// verify the correct methods being called
verify(beaconSender, times(1)).startSession(eq(session));
verify(beacon, times(1)).reportCrash(eq(errorName), eq(reason), eq(stacktrace));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small info: AFAIK the eq() are not necessary in this case

retAction = rootAction.leaveAction();
assertThat(retAction, is(nullValue()));

// verify that beacon cache is now empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// verify that open child actions are now empty

@DaRoli
DaRoli merged commit ad862a0 into Dynatrace:master Feb 7, 2018
@DaRoli
DaRoli deleted the feature/unittest-core branch February 7, 2018 12:43
openkitdt pushed a commit that referenced this pull request Jul 17, 2019
…e-1.3.3 to release/1.3

* commit '9223f63d72824a5a05a05b6cb41eb3777c7171a9':
  Prepare to release version 1.3.3

GitOrigin-RevId: 776b7a33897fb3bd6e7fc68cb63ef5cce65876b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants